JStefan Posted October 2, 2009 Share Posted October 2, 2009 Hi all, I am trying to make a self updating content web site and I managed to write the database records updating php`sn with help from you guys, thank you very much. At the moment I got stuck writting the records display page, I am actually trying to modify a script from a book. Here is my code at the moment: <?php include ("hara2.php"); $db = mysql_connect($HOSTNAME, $USERNAME, $PASSWORD, $DATABASE) or die("Couldn`t connect to server"); mysql_select_db("paintings") or die("Couldn`t connect to database"); $query = "select name, image, description, price from items where catlink=\"2\""; $res = mysql_query($query); if (!$res) error_message(sql_error()); echo "<table cellspacing='10' border='0' cellpadding='0' width='100%'>"; echo "<tr><td colspan='5' style='text-align: right'> Click on any picture to see a larger version. <hr /></td></tr>\n"; while ($row = mysqli_fetch_assoc($res)); echo "<tr>\n"; echo " <td style='font-weight: bold; font-size: 1.1em'>{$row['name']}</td>\n"; echo " <td style='font-weight: bold; font-size: 1.1em'>{$row['description']}</td>\n"; echo " <td style='font-weight: bold; font-size: 1.1em'>{$row['price']}</td>\n"; echo " <td style='font-weight: bold; font-size: 1.1em'>{$row['petName']}</td>\n"; echo "<td><a href='../images/{$row['image']}' border='0'> <img src='../images/{$row['image']}' border='0' width='100' height='80' /> </a></td></tr>\n"; mysql_close($db); ?> The apache error code log says: PHP Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, resource given in C:\\apache\\htdocs\\giulianoStore\\showitem.php on line 14 The browser output at the moment is a blank page with a placeholder link for the image. The image willdisplay if i click on the image placeholder. Thank you in advance for your help, Cheers, Julian Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/ Share on other sites More sharing options...
trq Posted October 2, 2009 Share Posted October 2, 2009 Your mixing the mysqli* extension with mysql*, they are two different things. Change mysqli_fetch_assoc to mysql_fetch_assoc. Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929355 Share on other sites More sharing options...
JStefan Posted October 3, 2009 Author Share Posted October 3, 2009 Hi changed mysqli to mysql same result still, thanks for help Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929431 Share on other sites More sharing options...
JStefan Posted October 3, 2009 Author Share Posted October 3, 2009 Hi again, by changing mysqli to mysql the php warning is not generated anymore but still no result rows are displayed. The table is not empty, it has 5 records. Thanks, Julian Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929435 Share on other sites More sharing options...
.josh Posted October 3, 2009 Share Posted October 3, 2009 - you are not selecting petName from your db. - make sure your path/to/image is correct. You are using ../ which makes it look for the image in the directory above the script's directory. - does your 'image' value contain the extension, or just the image name? - Make sure the image actually exists, as well. - put this in your script: echo "<pre>"; print_r($row); does it show your expected values? You have a (!$res) condition that calls some custom function. What does that function do? simply echo the mysql_error()? because if the query simply didn't return any results, the function will get triggered, but there is no mysql_error() generated from a query that simply returns 0 results. Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929439 Share on other sites More sharing options...
JStefan Posted October 3, 2009 Author Share Posted October 3, 2009 petName error fixed. I added echo "<pre>"; print_r($row); in script and does not return any result. Cheers, Julian Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929500 Share on other sites More sharing options...
JStefan Posted October 3, 2009 Author Share Posted October 3, 2009 Hi guys, this time I fixed it myself The issue was (after I researched a bit the net) that the echo statments which actually extract data from database had 2 be enclosed into a pair of {} paranthesis and no ; has to be after fetch statement or closing } I do apreciate your time and do not worry, i will be back with more q. soon Cheers Julian Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929509 Share on other sites More sharing options...
.josh Posted October 3, 2009 Share Posted October 3, 2009 hmm... well what you had before works for putting the first row of results into $row, so if you were only expecting 1 row to be returned, then that should have worked. If it is now working by wrapping it in brackets, that means you got more than 1 row returned, and (at least) the first row returned has a bunch of empty/null cells... how about confirming this by rightclick > viewsource and seeing if you have a bunch of "extra" empty html tags.... Quote Link to comment https://forums.phpfreaks.com/topic/176326-solved-php-script-to-dispaly-database-records-in-rows/#findComment-929659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.