Hello all
I am currently trying to teach myself some PHP and mySQL work in order to build a DB driven website.
I have a table in my database which stores information about a product eg (product name, price, description, image(set as a blob))
What I want to do is list all the items in this table in a webpage with the image showing following by the name and price of the item under it, something similar to the way Game.co.uk website displays their product information
I also would like when an item has been clicked on to show a new page with all the item's details.
Are there ay templates any knows of or has which I could go by as I am struggling to get this working
Kind Regards
Akin
Displaying records from a mySQL DB
Started by aakinn, Mar 09 2010 05:25 AM
37 replies to this topic
#1
Posted 09 March 2010 - 05:25 AM
|
|
|
#2
Posted 09 March 2010 - 06:32 AM
You'd need 3 pages. The products page which displays all products, the image which will display the image, and the product details page which will show all the details about the product.
<?PHP
//display all products
$query = mysql_query("SELECT * FROM `products`") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'">'.$row['name'].'</a>';
}
<?PHP
//display image
$id = $_GET['id'];//FILTER!!
$query = mysql_query("SELECT `image` FROM `products` WHERE `id`='$id'") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
$im = imagecreatefromstring($row['image']);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
}
<?PHP
//display full product
$id = $_GET['id'];//FILTER!!
$query = mysql_query("SELECT * FROM `products` WHERE `id`='$id'") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
}
#3
Posted 09 March 2010 - 07:44 AM
Excellent thats worked like a charm thanks alot mate just another quick thing
When im formatting the output I want each image to appear side by side/horizontally with the details of the items below the image so far I have this
...//display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"> </td>
</tr>
<td>'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
This displays the details below the images as I want but each record is shown vertically, how would I get the images to appear side by side?
Thanks
When im formatting the output I want each image to appear side by side/horizontally with the details of the items below the image so far I have this
...//display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"> </td>
</tr>
<td>'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
This displays the details below the images as I want but each record is shown vertically, how would I get the images to appear side by side?
Thanks
#4
Posted 09 March 2010 - 07:51 AM
Try this
<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a></td>
<td><a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
#5
Posted 09 March 2010 - 07:57 AM
I have tryed that already, that displays the image in one column with the details in a column next to it
I have been toying with it for some time now and cannot get it to display the images in one row and the details in a row below
I have been toying with it for some time now and cannot get it to display the images in one row and the details in a row below
#6
Posted 09 March 2010 - 07:59 AM
Oh, sorry. I misunderstood.
<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<table border="1" cellpadding="10">
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a></td>
</tr>
<tr>
<td><a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>
</tr>
</table>';
}
I think you just forgot to close the tr tag.
#7
Posted 09 March 2010 - 08:04 AM
That is still producing the images below one another and not side by side
The code was exactly the same as I had and it does seem to make sence but displays as soo
[IMAGE]
[Image details]
[IMAGE]
[Image details]
[IMAGE]
[Image details]
Where it should be
[IMAGE] [IMAGE] [IMAGE]
[Image details] [Image details] [Image details]
:cursing:
The code was exactly the same as I had and it does seem to make sence but displays as soo
[IMAGE]
[Image details]
[IMAGE]
[Image details]
[IMAGE]
[Image details]
Where it should be
[IMAGE] [IMAGE] [IMAGE]
[Image details] [Image details] [Image details]
:cursing:
#8
Posted 09 March 2010 - 08:07 AM
<?PHP //display all products
$query = mysql_query("SELECT * FROM tblItems") or die(mysql_error());
echo '<table border="1" cellpadding="10"><tr>';
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a><br />'.
'<a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>';
}
echo '</tr></table>';
}
#9
Posted 09 March 2010 - 08:09 AM
Thats the one
There was an extra } in there but took it out and worked!
Thanks alot it is very much appreciated!!
:thumbup:
There was an extra } in there but took it out and worked!
Thanks alot it is very much appreciated!!
:thumbup:
#10
Posted 09 March 2010 - 09:10 AM
How would I be able to specify a new row to start? as currently the data outputs in one continious row.
I have put the table in a div tag and the width has been set to 600px yet the table continues past the tags specified width and carrys on showing in one continous line
I have put the table in a div tag and the width has been set to 600px yet the table continues past the tags specified width and carrys on showing in one continous line
#11
Posted 09 March 2010 - 09:20 AM
aakinn said:
How would I be able to specify a new row to start? as currently the data outputs in one continious row.
I have put a width attribute on the table but this does not seem to make any difference. When I add more records it continues to carry on off the side of the page
I have put a width attribute on the table but this does not seem to make any difference. When I add more records it continues to carry on off the side of the page
$i = 0;
while($row=mysql_fetch_assoc($query)) {
//format the output
echo '<td><a href="fullProduct.php?id='.$row['id'].'"><img src="image.php?id='.$row['id'].'"></a><br />'.
'<a href="fullProduct.php?id='.$row['id'].'">'.$row['name'].'</a><br />£'.$row['price'].'</td>';
if(($i%4)==3) {
echo '</tr><tr>';
}
$i++;
}
#12
Posted 09 March 2010 - 12:19 PM
Ive not seen that clause in an if statement before what exactly does it doo? It dont look quite right to me and an error is being thrown on line 56
Parse error: syntax error, unexpected T_ECHO in /home/ka751/public_html/WAT/products.php on line 56
Line 56 being
"echo '</tr><tr>';"
But something is telling me its with the clause in the IF statement
Parse error: syntax error, unexpected T_ECHO in /home/ka751/public_html/WAT/products.php on line 56
Line 56 being
"echo '</tr><tr>';"
But something is telling me its with the clause in the IF statement


Sign In
Create Account


Back to top










