Forum Moderators: coopster

Message Too Old, No Replies

How does NULL work?

         

inveni0

8:57 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Here's what I have:

A table with several rows. Each row has 11 columns... The first column is the unique ID. The remaining ten are varchar columns meant to hold the filename of a given image (for instance [primarykey]1.jpg, [primarykey]2.jpg, etc.) I then have a javascript photo browser, where each photo name is loaded dynamically into a list with a repeating region assigned:

<option name="<php code here>">

This all works fine, however, not all rows have 10 photos. So, I need to know how NULL works. Can I code my option list so that it will not insert another entry if the corresponding field is NULL?

How would anyone recommend going about this?

jatar_k

9:05 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> for instance [primarykey]1.jpg, [primarykey]2.jpg

if you are using a repeated name like that why not just have 2 columns?

id and number of pics

then you could just loop it to create the names

$i = 0;
while ($i <= $numpics) {
echo '<option name="',$id,$i,'.jpg">';
$i++;
}

where $id is the primary key from any given row and $numpics is the number of images in that same row

inveni0

9:37 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Hey, good thinking! That'll work. I'll have to rearrange a few things, but that'll do the trick.

One note, however, I have to initially set the value of $i to 1...otherwise it inserts one extra photo (the 0 value).

Thanks again!

jatar_k

9:39 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> value of $i to 1

hehe, good point