Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2005
    Posts
    5

    Unanswered: Fecth Array problem

    PHP Code:
    $list_query mysql_query("SELECT DISTINCT(`name`) FROM list WHERE approved = 'yes' ORDER BY name");
    while(
    $list_get mysql_fetch_array($list_query))
    {
    $list_query_again mysql_query("SELECT * FROM `list` WHERE name = '$list_get[name]' AND approved = 'yes'");
    $list_get_again mysql_fetch_array($list_query_again);
    $report_query mysql_query("SELECT * FROM `list` WHERE name = '$list_get[name]' AND approved = 'yes'");
    $report_count mysql_num_rows($report_query); 
    This is an extract from my code. When it echos the names, if it get to a name called "Gojita'Mu" with an apostrifie(?) in it, it causes an error. Is their any way of solving this? I've tried to rearrange " to ' and vice versa, but I got nothing.

    Edit, my cpanel info says im on version 4.0.23-standard mysql
    Last edited by steveoo; 03-06-05 at 06:26.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you would need to replace the single apostrophe with two of them in a row, as in ...
    Code:
     ... where name = 'Gojita''Mu'
    however, by doing a query inside a loop, you are severely crippling your application

    what is this piece of code attempting to do?

    it looks like you're just looping through the entire list table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2005
    Posts
    5
    It's just selecting some "reports" in a table. Each report has a name date etc and weather or not if its been approved. Because its in one table many reports could be the same name, so I made it select only 1 and echo the name.

  4. #4
    Join Date
    Mar 2005
    Posts
    5
    Oh I'm also doing the while loop because I've only selected the name, and I'm just wondering if I can put a "*" their now. I'll test it.

  5. #5
    Join Date
    Mar 2005
    Posts
    5
    Hum nope. I'm, totaly confused now.

    Is they another way to stop this error without editing the myql database andjust the code? When I edit the database it edits the name and shows two, where as id rather have 1 of those ' xP

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    no, what i meant in post #2 was that you need to replace one quote with two in your SQL, not in the database

    you specify the value here --

    ... WHERE name = '$list_get[name]'

    you have to do something in php so that when you substitute the actual value of $list_get[name] into the SQL, each single quote inside the name is replaced by two of them

    how you do this in php is another matter, i don't do php so i can't help you there
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  7. #7
    Join Date
    Mar 2005
    Posts
    5
    Thank you for your help, it's working. :]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •