Current location: Hot Scripts Forums » Programming Languages » PHP » mysql query problem (very important for me...)


mysql query problem (very important for me...)

Reply
  #1 (permalink)  
Old 07-23-05, 05:35 AM
pedroso pedroso is offline
New Member
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
mysql query problem (very important for me...)

Hello!
I'm not a professional programmist, but I create now rather serious project, and -
as You know - sometimes I have problems with php or mysql...
Now I have terribly problem with one mysql query (...) - I need to have
"nr" or "id" in this query, but I can't do it... Everything, what I do - it's always
wrong, incorrect, and - it doesn't work... The part of the script looks like:

//
$question = "select * from data_table where ".$finding_method." like '%".$phrase."%' ORDER BY nr DESC ";
$result = mysql_query($question);
$howmany_founded = mysql_num_rows($result);

echo '<p>The number of founded elements: '.$howmany_founded.'</p>';

echo " ... etc...
//
So, I need a "nr" or "id" in this query, because I have to make the links
with results of this query, and without a "nr" or "id" it doesn't work correctly,
because it "don't know" which rekord of the data table should be displayed...
I try add something like : "and nr=$nr" ( $question = "select * from data_table where ".$finding_method." like '%".$phrase."%' and nr=$nr ORDER BY nr DESC " into query $question, but it still doesn't work...
If You can help me - I thank you very much, if not - I thank you too... bye-bye
Sorry for my english - it isn't my native language, unfortunately - P.P., Warsaw,Poland
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-23-05, 05:55 AM
shadi's Avatar
shadi shadi is offline
Wannabe Coder
 
Join Date: Aug 2004
Location: EGY
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
hi ,

i don't get what is the problem for sure , but for my knowledge this part of query
"ORDER BY nr DESC"

doesn't matter when calling the function mysql_num_rows();
so better remove it.


what does the variable $finding_method in the query stands for ?


bye
__________________
Email : write2shadi at gmail dot com
MSN : write2shadi at gmail dot com
Aim : shadiaim7
Skype: shadi_skype
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-23-05, 08:31 AM
pedroso pedroso is offline
New Member
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi - thank You for your answer - the script with a part: "ORDER BY nr DESC" works correct (I need, the results in this order), but when I add "and nr = $nr" as a requirement, it doesn't work... You understand - when i get list of results, for example:
result1
result2
result3
etc...
I want the results as a links to the sites, which displayed content of the table, in the way:
result1 - nr (id) of result1, and the rest of the rekords result1
result2 -nr (id) of result2 and the rest of the rekords result2
result3- nr (id) of result3 and the rest of the rekords result3
etc...
If I get results after query, I have "results" only, after that, I need the results should be links (heads of the links) to the sites, which displayed rest of their contents, and in this momment I need the "nr(or id)", because - in other way - the link (which is result of the query) "dont know" which rekord of the data base table should be displayed...

greetings for You - Pedroso
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-23-05, 12:08 PM
pedroso pedroso is offline
New Member
 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
$finding_method - it means "the way (manner, fashion) of the search in the database..."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-24-05, 02:45 AM
shadi's Avatar
shadi shadi is offline
Wannabe Coder
 
Join Date: Aug 2004
Location: EGY
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
did you surrounded the variable $nr with signle quotes ?

example :

Quote:
$question = "select * from data_table where ".$finding_method." like '%".$phrase."%' and nr = '$nr' ORDER BY nr DESC "
__________________
Email : write2shadi at gmail dot com
MSN : write2shadi at gmail dot com
Aim : shadiaim7
Skype: shadi_skype
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 07-26-05, 02:09 AM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
The query looks good. The order by will not really hurt anything even if all you do is use mysql_num_rows();. Try running:

Code:
$result = mysql_query($question) or die (mysql_error());
This will tell you what is wrong in some detail. Also, check your error logs which might be easier then using the above query. Also, if you are looking for numbers in the where clause, you do not need to quote them.

Code:
WHERE nr = 1 ORDER BY nr DESC
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Distinct Query problem FunkyM PHP 20 02-28-07 09:33 AM
MySQL Query problem Spreegem PHP 4 08-18-04 07:11 PM
MySQL Expert Required!! Advanced Query Problem bluey_the_punch PHP 1 02-28-04 02:37 PM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 12:28 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.