Jump to content

Recommended Posts

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

- 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.

 

 

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

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....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.