Jump to content


This topic is now archived and is closed to further replies.


mySQL php data-generated array

Recommended Posts


This is a mySQL / php question. Thanks in advance for anyone who can help me with this; I am very close and assume my loop is in the wrong place but just can't quite get it.

What I want is to have two text boxes created; one for the
$u_data["url"] and another for the u_data["material"]. I need
them to stay connected. So I want an array that holds a $key of $u_data["url"]
and a $value of $u_data["material"]. Then I want to create 8 text boxes, and
if the above data exists, then populate the boxes with that data; otherwise leave them

I have done this and get redundancy of information or I only get the number
of boxes for the number of filled variables. HERE'S THE CODE:

$url_sql = "SELECT a.title, b.title, b.url, b.material
FROM mprogram_library AS a
LEFT JOIN web_url AS b ON (a.title = b.title)
WHERE a.title = '".$id."'";

$url_rval = mysql_query ( $url_sql );
$rows = mysql_num_rows ( $url_rval );
$url_data = array();

while ( $u_data = mysql_fetch_assoc ( $url_rval ) ) {
$url_data[sizeof( $url_data )] = $u_data["url"];

for($i=0;$i<8;$i++){ ?>

<input size="20" type="text" name="web_url[<?php echo $i; ?>]"
id="web_url[<?php echo $i; ?>]" value="<?php
echo isset( $url_data[$i] )?$url_data[$i]:"";

} // End For

Thanks again if you can help me...Emily

Share this post

Link to post
Share on other sites


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.