Jump to content

[SOLVED] While Statement question


acctman

Recommended Posts

I have a While statement below that echos the results from my DB but i also need the mp3_id number it grabs from the DB to use in my javascript below that. how can I get it to output $en['mp3_id'] after the While process has ended?

 

<?
$mp3user = mysql_query("SELECT `mp3_id`,`mp3_userid`,`mp3_title` FROM `rate_mp3s` WHERE `mp3_userid` = '".$en['m_id']."'");

echo "<ul style=\"margin-left: 210px;\">\n";
$counter = 1;
while($en = mysql_fetch_array($mp3user)) {
echo "<li>MP3 " .$counter. " : <span id=\"mp3title-".$counter."\">".$en['mp3_title']. "</span> | <a href=\"process_mp3.php?user=" .$en['mp3_userid']. "&mp3=" .$en['mp3_id']. "\">Delete</a></li>\n";
$counter++;

}
echo "</ul>\n";

echo	"\n";
echo	"<script type=\"text/javascript\">\n";
echo	"\n";	

// This section needs to retrieve mp3_id from $en = mysql_fetch_array($mp3user)
echo	"new Ajax.InPlaceEditor('mp3title-1', '/process_mp3.php?mp3=" .$en['mp3_id']. "');\n";
echo	"new Ajax.InPlaceEditor('mp3title-2', '/process_mp3.php?mp3=" .$en['mp3_id']. "');\n";
echo	"new Ajax.InPlaceEditor('mp3title-3', '/process_mp3.php?mp3=" .$en['mp3_id']. "');\n";

echo	"\n";
echo	"</script>\n";

?>

Link to comment
Share on other sites

Save them into an array.

while($en = mysql_fetch_array($mp3user)) {
$mp3IDs[] = $en['mp3_id'];
echo "<li>MP3 " .$counter. " : <span id=\"mp3title-".$counter."\">".$en['mp3_title']. "</span> | <a href=\"process_mp3.php?user=" .$en['mp3_userid']. "&mp3=" .$en['mp3_id']. "\">Delete</a></li>\n";
$counter++;
}
...
foreach($mp3IDs AS $mp3ID){
   echo "new Ajax.InPlaceEditor('mp3title-1', '/process_mp3.php?mp3=" .$en['mp3_id']. "');\n";
}

 

etc.

 

Or you could make a big string of the Ajax code in the while loop and print it later.

Link to comment
Share on other sites

Save them into an array.

while($en = mysql_fetch_array($mp3user)) {
$mp3IDs[] = $en['mp3_id'];
echo "<li>MP3 " .$counter. " : <span id=\"mp3title-".$counter."\">".$en['mp3_title']. "</span> | <a href=\"process_mp3.php?user=" .$en['mp3_userid']. "&mp3=" .$en['mp3_id']. "\">Delete</a></li>\n";
$counter++;
}
...
foreach($mp3IDs AS $mp3ID){
   echo "new Ajax.InPlaceEditor('mp3title-1', '/process_mp3.php?mp3=" .$en['mp3_id']. "');\n";
}

 

etc.

 

Or you could make a big string of the Ajax code in the while loop and print it later.

 

$en['mp3_id'] is blank when echo'ing on the Ajax line at the bottom

Link to comment
Share on other sites

jesirose thanks for all the help one more small fix

 

 

since the Ajax line is not being looped... the mp3title-1,2, and 3 needs to be created. I tried using the counter like I did above but that didn't work.

 

foreach($mp3IDs AS $mp3ID){
$counter = 1;
echo	"new Ajax.InPlaceEditor('mp3title-".$counter."', '/process_mp3.php?mp3=".$mp3ID."');\n";
$counter++;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.