Page 1 of 1

Image link in Mysql

Posted: Mon Aug 25, 2003 6:01 pm
by Testor
Hi,

Working on a quiz script, wanted to add images to certain questions that need an image to clarify things. So, not all questions have images associated with them.

in the db(mysql) I added a field in the questions table and called it image, in this field I put the link to the images ex: /images/figure1.gif

My problem is that I'm unable to come up with the proper mysql query nor that I'm able to make the if statement present the image if there's one in the certain question row for example.

if($image){
echo "/images/$image";}

the mysql query, I don't know whether I shoould fetch row, num rows or what?

A quick run code would be very appreciated as I exausted everything. Nothing on the net, and certainly I'm new to this.

Thanks.

Posted: Mon Aug 25, 2003 7:09 pm
by JAM
Well, depending on what else you have stored, I can only give you the basic examples...

Code: Select all

<?php
// get 5 questions (rows)
$result = mysql_qyery("select question, image from table where id = '1' limit 5");

while ($row = mysql_fetch_array($query)) {
 // the question will of course be there i assume...
 echo 'Question: '. $row[0];
 // is the next value empty? if not = image = print it...
 if (!empty($row[1])) { echo '<img src="'.$row[1].'">'; }
}
Hope it gave you some help.

Posted: Mon Aug 25, 2003 9:24 pm
by Testor
Jam,

Thanks much, it certainly got me started, I worked on it for a while. First nothing happened, but then I got it to display the image but with every question :lol:

Yes I do have other stuff in the table like questionid, the question text, answers etc.. the image field is actually in row[10].

I do have a $query that selects from the questions table and that works fine.

Your code seems to be the one to do the trick I just have to keep working on it.