How to create a Hyperlink from a MySQL record set with PHP?


Problem :

I'm a complete beginner with HTML/CSS/PHP/MySQL, and I am using XAMPP to run a local MySQL/Apache server for testing purposes. I decided to create a simple page as a learning exercise that will create a table with data read from a MySQL table.

I have a MySQL table with 2 columns: Title and link. The 'Title' column lists the name of a Steam game, while the 'link' column contains a link to the Steam store page for that game.

I have done some searching to get a basic idea of how to do this, and I've almost got it working, but for some reason the data from the 'Title' column is displayed horizontally instead of vertically.

I'm a brand new member so I can't post images yet, but here's a link to a screenshot to clarify: http://i.imgur.com/kQPIrKX.png

I want Far Cry 3 to be listed vertically underneath of //N.P.P.D. RUSH, but instead it is listed to the right.

and here is the code:

<body>

<h1>Steam</h1>

<?php
$con=mysqli_connect('localhost','root','password','test1');
// Check connection
if (mysqli_connect_errno())
{
echo 'Failed to connect to MySQL: ' . mysqli_connect_error();
}

$result = mysqli_query($con,'SELECT * FROM steam ORDER BY Title');

echo '<table border=1>
<tr>
<th>Title</th>
</tr>';

while($row = mysqli_fetch_array($result))
{
echo '<td><a href="'.$row['link'].'">'.$row['Title'].'</a></td>';
}
echo '</table>';

mysqli_close($con);
?>

<a href="#" onClick="history.go(-1);return true;">previous</a>

</body>
</html>

I know I'm overlooking something simple, but I'm too much of a beginner to know what.

Thanks in advance.



Solution :

Table row (tr) tags for each of the table data (td) elements?

while($row = mysqli_fetch_array($result))
{
 echo '<tr><td><a href="'.$row['link'].'">'.$row['Title'].'</a></td></tr>';
}

http://www.w3.org/wiki/HTML/Elements/table


Mysql Tutorials

Mysql Howto..

How can I use Entity Framework on an object graph past a depth of 2 with MySQL Connector / NET?

MySQL: how to index an “OR” clause

how to return row count of mysql sub query

how die or print mysql has gone away error exact reason?

How to add a column to a table from another table in Mysql?

How to transform a normalised data set using PHP?

How to count records that equal or add up to a certain timeshift?

How to use mysql full text search when title and text are in two separate tables?

how to numbered ascending the select results from mysql?

How to design a “view” in MySQL that will get the results I am looking for?

Teach an M.B.A. the intricacies of Microsoft SQL Server (and how's it different from MySQL?) [closed]

How to securely maintain user authentication through a third party API?

MySQL: How to use the result of one INSERT in another INSERT

How to send Array of values from android to php

I'm using mybb, how can I find the top 5 threads that has the most readers currently?

phpMyAdmin won't let me login - no error shown

how to update data to gae localhost server from mysql

How to select data rows from MySQL if i have few date rows separately?

how to indent results of mysql SELECT INTO OUTFILE

how to convert time(mktime) to date(mm/dd/yyyy) in php?

Hibernate - How to use a generator to create a primary key for a reference table?

How to efficiently INSERT a large number of rows in MySQL?

How to correctly structure schema

How to remove some data not needed on new row from mysql query with rollup

How to use alphanumeric fields with BETWEEN clause in Mysql?

How to select fields from three different tables in MySQL

How to make MySQL query run as fast as possible?

MySQL How to count multiple entries while maintaining unique fileds

How to join mysql tables

How to send a vector to php file?