...

View Full Version : Database contents not showing



Kersh86
02-23-2012, 06:30 PM
<?php
include '/database/config.php';
include '/database/open.php';

$query = "SELECT * FROM slideshow";
$res = mysql_query($query) or die('Query Error: '.$query .'<br /><br />'. mysql_error());

while($row = mysql_fetch_array($res, MYSQL_ASSOC) or die('Result Error: '.$res.' '. mysql_error()));
{
echo "<div class='slide'>
<h2>{$row['Brand']}</h2>
<p><a href='#'><img src='{$row['img']}' alt='An image that shows a {$row['Brand']} style shoe' width='215px' height='145px' border='0' /></a>
{$row['Details']}</p>
</div>
";
}

include '/database/close.php';
?>

I get Result Error: Resource id #6

where am i going wrong, my database has something inside the table, it connects fine, so whats going on

mlseim
02-23-2012, 06:35 PM
I see column names like this:

img
Brand
Details

Brand and Details are capitalized, "img" is not.
Did you type all of them correctly?
Is that what they are officially named in your database?


.

tangoforce
02-23-2012, 06:37 PM
This:
die('Result Error: '.$res.' '. mysql_error()));

Your query for some reason, isn't correct so that part is trying to run.

$res is a mysql resource so PHP can't print it but will instead tell you its a resource.

Run your query through the SQL page in phpmyadmin and see if you get an error.

Also in your echo, you're using things like $row['img'] - yet this is inside a double quoted string so you will get a warning about that. Remove the single quotes - they're not needed inside a string.

Fou-Lu
02-23-2012, 06:50 PM
The problem is that mysql_fetch_* is designed to return false when its complete. Adding the or die in there means when you've iterated the entire recordset, the final occurrence causes it to issue a die.
Remove the or die from the mysql_fetch_array.

Kersh86
02-23-2012, 07:02 PM
The problem is that mysql_fetch_* is designed to return false when its complete. Adding the or die in there means when you've iterated the entire recordset, the final occurrence causes it to issue a die.
Remove the or die from the mysql_fetch_array.

Thanks for the reply. I'll try this when I get back into work tomoz.

Kersh86
02-24-2012, 12:41 PM
The error message has gone now but it still wont show the contents i know there is content,

Database dispair_db
Table structure for table slideshow
Column Type Null Default
ID int(11) No
brand varchar(30) No
img varchar(75) No
desc text No

Dumping data for table slideshow
1 Albion /images/AW12/albion-bordeaux.png Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec pretium arcu non velit. Phasellus adipiscing auctor lorem. Curabitur in urna ut purus consequat sollicitudin. Phasellus ut diam. Cras magna libero, tempor id, venenatis sit amet, venenatis et, dui.

this is the content yet it wont show it from the code which is similar to the code above except all names in lower_case and i have removed the "or die()"

any advice would be helpful

if you want me to repost the code again let me know

mlseim
02-24-2012, 01:21 PM
You fixed the upper/lower case problems ... and
there is no column called "Details" ... $row['Details'],
so you also fixed that ...

can you repost your script now since you fix things?



.

Kersh86
02-24-2012, 02:33 PM
include '/database/config.php';
include '/database/open.php';

$query = 'SELECT * FROM slideshow';
$result = mysql_query($query) or die('Query Error: '.$query .'<br /><br />'. mysql_error());

while($row = mysql_fetch_assoc($result))
{

echo " <div class='slide'>
<h2>".$row['brand']."</h2>
<p><a href='#'><img src='".$row['img']."' alt='An image that shows the ".$row['brand']." style shoe' width='215px' height='145px' border='0' /></a>"
.$row['desc']."</p>
</div>
";
};
include '/database/close.php';

i fixed it all now the error was a mis type i had a ; at the end of the while before the {

Fou-Lu
02-24-2012, 02:47 PM
Ah yes didn't even notice that.
; at the end of a while loop is true once and only once on the last iteration.
For an example:


<?php

$a = range(1, 10);
while (($cur = current($a)) && next($a) or die('all done'));
{
print $cur . PHP_EOL;
}


Will simply execute the die. If you remove the semi-colon, it will print 1-9 then die. The next() is the bound check on this one, so it will never make it to the 10.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum