If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Fecth Array problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-05, 05:20
steveoo steveoo is offline
Registered User
 
Join Date: Mar 2005
Posts: 5
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 05:26.
Reply With Quote
  #2 (permalink)  
Old 03-06-05, 06:51
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-06-05, 07:05
steveoo steveoo is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 03-06-05, 07:31
steveoo steveoo is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 03-06-05, 07:50
steveoo steveoo is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 03-06-05, 07:53
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 03-06-05, 09:51
steveoo steveoo is offline
Registered User
 
Join Date: Mar 2005
Posts: 5
Thank you for your help, it's working. :]
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On