Hi ya,
I have just started using php and have become stuck!!!
I have a query that pulls results in to a table, but it is repeating the same results in to 2 tables next to each other. What I was trying to get a table so it looks like:
1 2
3 4
5 6
7 8
9 10
instead of
1 1
2 2
3 3
4 4
etc...
Also does anyone know how to make only 10 results per page and automatic add the prev and next links.
Thanks
<?php
// set database server access variables:
$host = "localhost";
$user = "user";
$pass = "pass";
$db = "db";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM products WHERE code LIKE 'T%' ORDER BY id";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table border=0 cellspacing=0 cellpadding=25px width=250px>";
while
($row = mysql_fetch_row($result)) {
// first cell
echo "<td><center><img src=".$row[4]."></center>";
echo "<center span='text'>".$row[1].
" - £$row[6] <br>" .
"$row[2] </span>";
// second cell - exact duplicate of one above
echo "<td><center><img src=".$row[4]."></center>";
echo "<center span='text'>".$row[1].
" - £$row[6] <br>" .
"$row[2] </span>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No items found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>