1

I'm kinda confused right now with this function I'm trying to edit. I would like to add the mysql_fetch_array to the feedback string. I'm pretty sure it's possible but can somebody point out the problem for me? The piece of code I'm trying to execute is in comments. And where's PRINTHERE, that where I want the mysql_fetch_array to spit out the results. Thx a lot!

foreach($_FILES as $k => $v){ 

    $img_type = "";

    ### $htmo .= "$k => $v<hr />";  ### print_r($_FILES);

    if( !$_FILES[$k]['error'] && preg_match("#^image/#i", $_FILES[$k]['type']) && $_FILES[$k]['size'] < $max_image_size ){

        $img_type = ($_FILES[$k]['type'] == "image/jpeg") ? ".jpg" : $img_type ;
        $img_type = ($_FILES[$k]['type'] == "image/gif") ? ".gif" : $img_type ;
        $img_type = ($_FILES[$k]['type'] == "image/png") ? ".png" : $img_type ;

        $img_rname = $_FILES[$k]['name'];
        $img_path = $upload_dir.$img_rname;

        copy( $_FILES[$k]['tmp_name'], $img_path ); 
        if($enable_thumbnails) make_thumbnails($upload_dir, $img_rname);
        /*
        mysql_connect("localhost", "", "") or die(mysql_error());
        mysql_select_db("");        
        $result = mysql_query("SELECT * FROM gallery_main ORDER BY datetime DESC");
        while($row = mysql_fetch_array($result))
          {
            $name=$row['name'];
            echo "<option value='$name'>$name</option>";
          }
         */ 
        $feedback .="<style>.stap1{display:none;}.stap2{display:block;}</style>
        <input name='src' style='width:400px;' type='hidden' value=\"$img_rname\"><br />
        <input name='thumbsrc' style='width:400px;' type='hidden' value=\"thumb_$img_rname\"><br />
        <select name='galleryname' id='galleryname'>PRINTHERE";
    }
}
2
  • Are you the Andrew Ng of Stanford machine learning fame? Commented Feb 19, 2012 at 0:00
  • 1
    No, Im not. Just another guy with same name. hehehe Commented Feb 19, 2012 at 0:13

1 Answer 1

1

Instead of echoing, store the results into a variable, like you did with $feedback.

$options = '';

while($row = mysql_fetch_array($result)) {
    $name=$row['name'];
    $options .= "<option value='$name'>$name</option>";
}

Then, append to $feedback

$feedback .= "<style>.stap1{display:none;}.stap2{display:block;}</style>
        <input name='src' style='width:400px;' type='hidden' value=\"http://www.djpassa.com/gallery/$img_rname\"><br />
        <input name='thumbsrc' style='width:400px;' type='hidden' value=\"http://www.djpassa.com/gallery/thumb_$img_rname\"><br />
        <select name='galleryname' id='galleryname'>" . $options;

Also, you need to select a database.

mysql_select_db("database_name");   
Sign up to request clarification or add additional context in comments.

10 Comments

Hmm somehow it's still not working i've added the whole php file to this address: codepad.org/Y505gazf
Assuming your query is correct and retrieves at least 1 result, you need to select a database.
I've removed the info for security reasons. Even with the correct login info it wont parse the list out. Any more clues???
Can you confirm any content is concatenated to $feedback? If there is none, then there may be an issue with your SQL credentials or query. Also, add </select> to close off the select tag, but this shouldn't make a difference.
hi i've updated the code. This is what I have now: codepad.org/GpQwqJw4 it does spit out $lol which is lol in plain text. But not the $options
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.