ionnnnutz Posted April 19, 2007 Share Posted April 19, 2007 i'm not sure if this query is really ok: $data = mysql_query("SELECT * FROM comp WHERE comp_am_id='.$user[id].' AND $field LIKE'%$find%'"); <?php require("includes/connect.php"); require ("includes/checklogin.php"); include ('includes/header.php'); if ($logged_in == 0) { echo "Nu esti logat! "; echo '<a href="login.php">Login</a>'; exit; } ?> <?php include ('includes/sidenav.php'); ?> <div style="font-family: 'trebuchet ms'; font-size: 12px; color: #ffffff;"> <form name="search" method="post" action="<?=$PHP_SELF?>"> Cauta: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="comp_nume">Nume companie</option> <Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option> <Option VALUE="comp_domeniu">Domeniu</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="cauta!" /> </form> <?php if ($searching =="yes") { echo "Rezultate <br>"; if ($find == "") { echo "Nu ai introdus termenul de cautat"; exit; } $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); [color=red]$user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' "); $user2=mysql_query($user3); $user=mysql_fetch_array($user3); $data = mysql_query("SELECT * FROM comp WHERE comp_am_id='.$user[id].' AND $field LIKE'%$find%'"); [/color] while($result = mysql_fetch_array( $data )) { echo $result['comp_nume']; echo " "; echo $result['comp_adresa_sediu_localitate']; echo " "; echo $result['info']; echo "<a href='detalii.php?ID=$result[comp_id]'>$result[comp_nume]</a>"; echo "<br>"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Nu am gasit termenul cautat!</div>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/ Share on other sites More sharing options...
mmarif4u Posted April 19, 2007 Share Posted April 19, 2007 Can u explain a little ur q. Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232940 Share on other sites More sharing options...
ionnnnutz Posted April 19, 2007 Author Share Posted April 19, 2007 i have 2 tables in database: one is "user" and the other is "comp". the link between these 2 tables is comp.comp_am_id = user.id . when i want to search the database, is this php querry correct? <form name="search" method="post" action="<?=$PHP_SELF?>"> Cauta: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="comp_nume">Nume companie</option> <Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option> <Option VALUE="comp_domeniu">Domeniu</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="cauta!" /> </form> <?php //This is only displayed if they have submitted the form if ($searching =="yes") { echo "Rezultate <br>"; //If they did not enter a search term we give them an error if ($find == "") { echo "Nu ai introdus termenul de cautat"; exit; } $user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' "); $user2=mysql_query($user3); $user=mysql_fetch_array($user3); //this goes through all the entries that you selected $data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% "); Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232945 Share on other sites More sharing options...
mmarif4u Posted April 19, 2007 Share Posted April 19, 2007 Yeh the query is right, r u get some error. Post it we will try to help u out. Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232953 Share on other sites More sharing options...
ionnnnutz Posted April 19, 2007 Author Share Posted April 19, 2007 the problem is that the querry don't display any result when it should. Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232958 Share on other sites More sharing options...
mmarif4u Posted April 19, 2007 Share Posted April 19, 2007 <form name="search" method="post" action="<?=$PHP_SELF?>"> Cauta: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="comp_nume">Nume companie</option> <Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option> <Option VALUE="comp_domeniu">Domeniu</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="cauta!" /> </form> <?php //This is only displayed if they have submitted the form if ($searching =="yes") { echo "Rezultate <br>"; //If they did not enter a search term we give them an error if ($find == "") { echo "Nu ai introdus termenul de cautat"; exit; } $user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' "); $user2=mysql_query($user3); $user=mysql_fetch_array($user3); //this goes through all the entries that you selected $data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% "); $data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% "); try this instead of the above: $data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% ") or error("Error executing query [$data]: " . mysql_error()); It will show the error. Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232963 Share on other sites More sharing options...
nikkieijpen Posted April 19, 2007 Share Posted April 19, 2007 $user=mysql_fetch_array($user3); has to be $user=mysql_fetch_array($user2); ?? Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232979 Share on other sites More sharing options...
ionnnnutz Posted April 19, 2007 Author Share Posted April 19, 2007 no error. i've browsed the database with phpmyadmin, and the error is somewhere...there. the field comp_am_id, (INT( 11 ) NULL DEFAULT) shows weird (entries like '/'. '0') when it should have the user_id automatically inserted Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232983 Share on other sites More sharing options...
ionnnnutz Posted April 19, 2007 Author Share Posted April 19, 2007 thank you mmarif4u and nikkieijpen. nikkieijpen u were right. i have to pay more atention next time Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232992 Share on other sites More sharing options...
mmarif4u Posted April 19, 2007 Share Posted April 19, 2007 Try the nikkieijpen post. Link to comment https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/#findComment-232995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.