Jump to content


mySQL php data-generated array

  • Please log in to reply
No replies to this topic

#1 emilyfrazier

  • Members
  • PipPip
  • Member
  • 15 posts

Posted 30 May 2006 - 08:11 PM


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

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users