Forum Moderators: coopster

Message Too Old, No Replies

query strings

how to send multiple variables

         

Grenz

10:11 am on Feb 16, 2010 (gmt 0)

10+ Year Member



Hi all

Im working on a project where I call a db, get some names and id's, which then are sendt to my flash video.

This is the PHP i got so far (with help from this forum):


/*this is the connection to the database */
$con = mysql_connect("localhost","-","-");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("-", $con);

$sql = "SELECT * FROM example ORDER BY id ASC";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);

for($i = 1; $i < $rows; $i++) {
$entryname[$i] =mysql_result[$result, $i, "imagename");
$entryid[$i] = mysql_result($result,$i,"id");
}


I want to send the variables as one string like:


n=$rows&imagename1=$entryname1&id1=$entryid1&imagename2=$entryname2&id2=$entryid2& etc. etc.;


Im stil new to php, so Im not sure how to make the string work properly.

Any help is greatly appreciated :-)

chadhaajay

12:42 pm on Feb 16, 2010 (gmt 0)

10+ Year Member



You can modify your for-loop with code below.

$str1 = "n=$rows";
for($i = 1; $i < $rows; $i++)
{
$entryname[$i] =mysql_result[$result, $i, "imagename");
$entryid[$i] = mysql_result($result,$i,"id");

$str1 .= "&imagename$i=$entryname[$i]&id$i=$entryid[$i]";
}
print $str1;


I've not tested it however I'm quite sure it will work.

Grenz

8:48 pm on Feb 16, 2010 (gmt 0)

10+ Year Member



Hi

Thanks a lot. It worked. I made some minor changes, but no problems.

Thanks again :-)

chadhaajay

3:35 am on Feb 17, 2010 (gmt 0)

10+ Year Member



I'm glad to be of help!