Jump to content

SundayDriver

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

SundayDriver's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, you and I posted at the same time. :-)
  2. OK, problem solved. :-) The problem was my fault really- the array was created from an uploaded text file of separated values. These values had spaces between the comma and the next value. This in turn created a space before every value that was sent to the query, except the first one. For this reason, the query could not find any value in the array except the first one. Instead of trimming each one, I just removed the space in the uploaded text file between songs, and will tell the eventual users of this system to do the same. So thank you KingPhilip, Blade280891, and redarrow.
  3. Hey, thanks, I didn't even think of that. Yes, the song appears title appears from that additional echo statement. Output: SELECT * FROM `songs` WHERE `songtitle`=' Eastbound Train' The songID still does appear though. I just hate not knowing whether it is the query or the while loop that is causing the issue. Hmm...I just realized there is a space in front of Eastbound... Let me "trim" it and see what happens.
  4. I just tried that, but still no songID output.
  5. I understand what you're saying, and I thank you for taking the time to respond. But try explaining this! Let's say I had the following code, where $songsalt is an array. Position 4 in the array contains the text value of "Eastbound Train". <?php $test1 = $songsalt[4]; echo $test1; $result = mysql_query("SELECT * FROM songs WHERE songtitle='$test1'") or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo $row['songID']; } ?> The output of the code only produces "Eastbound Train" which is just the original echoed value before the query even takes places. It does not produce the songID. Meanwhile, back in the mySQL database, there is clearly a songID and songtitle column, with Eastbound Train as the songtitle, and 72 and the songID. That's what I don't understand. If I took '$test1' out of the query, and replaced it with 'Eastbound Train', it DOES produce the songID of 72. So what doesn't php like about my variable?
  6. Go figure- when I ran that I got the songID for the last value in the array. (But what I was trying to do was output each of the songIDs for every value in the array.)
  7. When I ran that, "00001" appears. I guess that is the problem then, huh? The query is only returning one row? But how could that be...I know for a fact the text in each value of the array is exactly the same as is in the "songtitle" column of the "song" table. foreach ($songsalt AS $value) { $result = mysql_query("SELECT songtitle FROM songs WHERE songtitle='$value'") or die(mysql_error()); echo mysql_num_rows($result); } while ($row = mysql_fetch_array($result)) { echo $row['songID']; echo "<br>"; }
  8. Thank you both for the replies. Unfortunately, when I tried redarrow's code, it didn't work. There are still no errors though either.
  9. My first post here and I am asking for help. :-\ But this bug is killing me.... I have an array with bunch of text values in it ($songsalt). I know the contents of the array are intact because I can see them using the "print_r" function. When I run the below code, I see the "songID" for the first value in the array (position "0"), but that's it. No matter what I do, the foreach loop doesn't seem to want to look through the rest of the values in the array. Even if I get rid of the foreach loop, and pull anything out of the array manually, it still doesn't output the songID for anything but the array value at position "0". I am really baffled by this. ??? Any help really would be appreciated. Thanks for reading. (Note: The handle error code does not output an error.) foreach ($songsalt AS $value) { $result = mysql_query("SELECT songtitle FROM songs WHERE songtitle='$value'") or die(mysql_error()); if (!$result) { // Handle error echo 'Query failed. SQL: ', $sql, '<br />Error # ', mysql_errno(), ' Error msg: ', mysql_error(); exit;} while ($row = mysql_fetch_array($result)) { echo $row['songID']; echo "<br>"; } }
×
×
  • 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.