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 fonded 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
mysql query problem (very important for me...)
Moderator: General Moderators
You said you need nr or id in your query, what exactly do you mean by that? Does your database have nr or id as a value? If so then all you need to do is use a while loop to get it printed.. 
Oh i cleaned up the code of your query a bit, cause there's no need to user .$finding_method. if you put it between " and ".
Is this what you meant?
Oh i cleaned up the code of your query a bit, cause there's no need to user .$finding_method. if you put it between " and ".
Is this what you meant?
Code: Select all
$question = "select * from data_table where $finding_method like %$phrase%' ORDER BY nr DESC ";
$result = mysql_query($question);
$howmany_founded = mysql_num_rows($result);
while($row=mysql_fetch_array($result)) {
$nr=$row['nr'];
$id=$row['id'];
echo("$nr $id");
}Meaby you are recieving the primary key (key or id) through a URL?
Code: Select all
$id = mysql_escape_string($_GET['id']);
$query = "SELECT * FROM table WHERE id=$id";