PHP - Sql Select From: Display 1 Result
Okay so, I'm adding a reply feature to my text-board, and I'm wondering how I can select a single result from the DB
I've tried this $board = mysql_real_escape_string($_GET['board']); $thread = mysql_real_escape_string($_GET['thread']); $result = mysql_query("SELECT subject, name, id, timestamp, body FROM $board LIMIT $thread,$thread"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("<div id='html1' style='background-color:#F0E0D6;border:solid 1px #800000;font-family:arial; font-size: 12px; padding:2px; margin:2px;'><font color='#CC1105'>%s </font><font color='#117743'>%s</font> <font color='#800000'>Post # %s - %s<br />%s<br /></div>", $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6]); mysql_free_result($result); } ?> Kinda works but if I pu ?thread=56 then it would show thread 57, which in this example does not exist. Similar TutorialsHi, I have come up with the following code, I need it to get the details of several scattered products and echo the results, the trick is I don't want it to echo the results one after the other... I want to have the products scattered between unique text on the page but don't want to run the query several times for performance reasons. E.g.- PAGE to look like this: $Product_1 unique text/images $Product_2 $Product_3 unique text/images $Product_4 Current Code: Code: [Select] <? $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); while($row = mysql_fetch_array($result)) { $x = "1"; while ($x<=3) { echo $x; $Product = "Product_"; $Product = $Product.$x; echo $Product; $Product = $row['Product_ID']; echo $Product; $x++; echo $x; } } At the moment it returns the following results: Quote 1 Product_1 465 2 2 Product_2 465 3 3 Product_3 465 4 1 Product_1 475 2 2 Product_2 475 3 3 Product_3 475 4 A few problems... In Blue... it duplicates for product 465 In Red... It repeats again for 475 Also.... it starts with 465, but I want it to go in order as how it appears - $result = mysql_query("SELECT * FROM products where Product_ID IN (475, 465, 234, 567, 845)"); so should start with 475 I want to get the following result: Quote 1 Product_1 475 2 2 Product_2 465 3 3 Product_3 234 4 4 Product_4 567 4 (and so on.....) If anyone could provide me assistance with my troubled 'while loop' statement that would be much appreciated! Hi there
I am new to this forum and not much of a php expert. I hope you can assist me.
My problem is as follows:
I have a column consisting of several values (in this case: sceience, art, humanistics and music)
I would like to use the following mysqli query in order to count the appearances of each value in this column:
$query = "SELECT SUM (IF(department = 'science', 1, 0)) AS science, SUM(IF(department = 'art', 1, 0))-> AS art FROM new2"
I have tried lots of ways to loop the results but couldn't get the it working.
Can anyone suggest any idea?
Thanks
Hanan
$result = mysql_query("SELECT * FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' "); echo mysql_num_rows($result);This displays the total rows in the table. $result = mysql_query("SELECT COUNT(friend_system_accepter) FROM `friend_system` WHERE `friend_system_accepter` = '$myusername' "); echo mysql_num_rows($result);This displays '1', which is incorrect. I want to echo out the number of rows where 'friend_system_accepter' = $myusername Thanks Hello.
I'm having some issues with a select statement containing ABS().
Here's the select query:
"SELECT gadenavn, husnr, ABS(husnr - $husnr) AS husnr_range, postnr,db, shaping, dsl_node, ctr_node, db_ctr_luftlinje, bynavn FROM `TABLE 1`, Post_numre WHERE `postnr`=`postnummer` AND `gadenavn`=`$vejnavn` AND `postnr`=`$postnr` AND `husnr`>0 ORDER BY husnr_range ASC LIMIT 5"Now lets asume my variable "$husnr" is a value of 15. In my table I have the values for coulmn "husnr": 13,12,11,10,9 What really bugs me is the outcome doing af simple "while loop" is returning the values 12,11,10,9. What happened to 13?! printing the "husnr_range" values shows "3,4,5,6". What puzzles is the row missing, as I only get 4 results, with a "LIMIT 5". Can anyone explain why the last resulst isn't included? I am trying to update a mysql table called AvItems with the value 'Torso' in the Equip "section?" I have been through the forums and cannot see anything to match. I dont mind if the page looses the onsubmit() and has a button instead. Though I would like to update the database and link back to the same page: There is a display that shows the item that is currently equiped, I have put this in to show it works, or doesn't as the case may be. Hope I got the code /code right this time. many thanks in advance Andy Curtis Code: [Select] create table Items( ItemID integer unsigned auto_increment primary key, ItemName varchar(20) not null, Type varchar(10), UsedOn varchar(10), ); create table AvItems( AvItemID integer unsigned auto_increment primary key, AvID integer unsigned, ItemID integer unsigned, Equip varchar(8)); <?php $username="root"; $password="MyPassword"; $database="MyDataBase"; $AvName = "AndyJCurtis"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $AvAccR = mysql_query( " SELECT AvID FROM AvAcc WHERE AvName = '$AvName' " ); $AvID = mysql_result($AvAccR, 0, 'AvID'); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $Torso = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' AND UsedON = 'Body' "); $TorsoE = mysql_query(" select ItemName from AvItems, Items where AvItems.itemID = Items.itemID AND AvItems.AvID = '$AvID' And UsedON = 'Body' AND Equip = 'Body' "); if(mysql_num_rows($TorsoE) != 0) { $TorsoItem = mysql_result($TorsoE ,0,"ItemName"); //mysql_close(); ?> <title></title> <head></head> <body> <form action="http://localhost/CI/Equip2.php" method="post"> <table border=1> <tbody> <tr> <td>Torso<BR> <?PHP echo "$TorsoItem <BR>"; ?> <select name="Torso" onchange="submit();" value =" Update"> <?PHP while($TorsoRow = mysql_fetch_array($Torso)) { echo "<option value=\"".$TorsoRow['ItemName']."\">".$TorsoRow['ItemName']."\n </option>"; } ?> </select> </td> </tr> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php if($_POST['Torso'] == 'Update') { mysql_query("update AvItems set Equip = '' where Equip='Torso'") or die("cant update unequip"); mysql_query("update AvItems set Equip = 'Torso' where ItemID='{$_POST['ItemName']}'") or die("cant update equip"); } ?> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// </tbody> </table> </.form> </body> </html> Hey guys. Me again... Essentially what i am doing is pulling data from a MySQL database about the number of thumbnails on a page. The user can then change this using a <select> dropdown menu. How ever, i want the <select> to default to the amount already specified by the Database. I know i can do this by inserting a Selected attribute to one of the <options> but what is the best way of doing this? Heres my code.. $NumberOfThumbnails = mysql_result($data, 0,"NumberOfThumbnails"); <select name="numberofthumbnails"> <option value="0">None</option> <option value="2">2</option> <option value="4">4</option> <option value="6">6</option> <option value="8">8</option> <option value="10">10</option> <option value="12">12</option> <option value="14">14</option> <option value="16">16</option> <option value="18">18</option> <option value="20">20</option> <option value="22">22</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> </select> Thanks - Danny i have two tables, and i want to display data from the most recent entry of the two(i.e. display just one entry). i'm joining together 2 tables so that i can get this entry.Both tables contain the date, so i'm ordering the results of the query so that the most recent comes first. My tables a TOPIC topic_id topic _name section_sub_id date POST post_id post_name section_sub_id date I'm using the following code to get the last result, but nothing is being echoed $join =mysql_query("SELECT topic.*, post.* FROM topic LEFT JOIN post ON topic.section_sub_id=post.section_sub_id WHERE post.section_sub_id = " .$row2['section_sub_id']. " ORDER BY topic.date") or die("Select Error :" . mysql_error()); $latest= mysql_fetch_row($join); echo $latest['post.date']; i'm not sure if there is something wrong with the sql, or with the php. ANy help would be great Hi i got a search form and when im searhing for result i get nothing. i got 5 search fields : 1. Erea 2. category 3. subcategory 4. from price 5. to price if im not specifieing from price and to price i get blank result ,if i do specify the from price to price ,then i get the results. this is the code im using to get the results. Code: [Select] $sql=mysql_query("select * from posts where erea = '$erea' and category = '$category' and sub_category = '$subcategory' and price >= '$fromprice' and price <= '$toprice'"); what i want is to get the result even if i didnt specify the price from, to . thanx When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change I'm writing a highscore board for a game and I can only display one value from a DB... I don't know what I could be doing wrong. I've done this kind of DB work before. <?php $name = $_GET['lvl']; if($_GET['lvl']=="Strength"){ //1/21 $skill = "strlvl"; $exp = "strexp"; } else if($_GET['lvl']=="Attack"){ //2/21 $skill = "atklvl"; $exp = "atkexp"; } else if($_GET['lvl']=="Defence"){ //3/21 $skill = "deflvl"; $exp = "defexp"; } else if($_GET['lvl']=="Hitpoints"){ //4/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Range"){ //5/21 $skill = "rglvl"; $exp = "rgexp"; } else if($_GET['lvl']=="Magic"){ //6/21 $skill = "mglvl"; $exp = "mgexp"; } else if($_GET['lvl']=="Hitpoints"){ //7/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Prayer"){ //8/21 $skill = "prlvl"; $exp = "prexp"; } else if($_GET['lvl']=="Runecraft"){ //9/21 $skill = "rclvl"; $exp = "rcexp"; } else if($_GET['lvl']=="Slayer"){ //10/21 $skill = "sllvl"; $exp = "slexp"; } else if($_GET['lvl']=="Thieve"){ //11/21 $skill = "thlvl"; $exp = "thexp"; } else if($_GET['lvl']=="Agility"){ //12/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Firemaking"){ //13/21 $skill = "fmlvl"; $exp = "fmexp"; } else if($_GET['lvl']=="Woodcut"){ //14/21 $skill = "wclvl"; $exp = "wcexp"; } else if($_GET['lvl']=="Cooking"){ //15/21 $skill = "cklvl"; $exp = "ckexp"; } else if($_GET['lvl']=="Herblore"){ //16/21 $skill = "hblvl"; $exp = "hbexp"; } else if($_GET['lvl']=="Mining"){ //17/21 $skill = "mnlvl"; $exp = "mnexp"; } else if($_GET['lvl']=="Farming"){ //18/21 $skill = "frmlvl"; $exp = "frmexp"; } else if($_GET['lvl']=="Fishing"){ //19/21 $skill = "fshlvl"; $exp = "fshexp"; } else if($_GET['lvl']=="Smithing"){ //20/21 $skill = "smlvl"; $exp = "smexp"; } else if($_GET['lvl']=="Fletching"){ //21/21 $skill = "fltlvl"; $exp = "fltexp"; } else if($_GET['lvl']==""){ //0/21 echo "<center><br /><br />No skill selected!</center><br />"; } mysql_connect("mysql", "15557_test", "**************") or die("Could not connect: " . mysql_error()); mysql_select_db("15557_test"); //STARTS HERE $result = mysql_query("SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo"Skill: " . $name . "<br />"; printf("Player: %s - Rank: %s - EXP: %s<br />", $row[0],$row[1],$row[2]); mysql_free_result($result //ENDS HERE } ?> Code: [Select] SELECT DISTINCT(keywords_keyword), photos_extension FROM photos,photos_keywords,keywords,photos_websites WHERE photos_keywords_photo=photos_id AND photos_keywords_keyword=keywords_id AND photos_websites_website='3' ORDER BY keywords_keyword ASC this code gets all the correct websites, but I would like to get one website per keywords_keyword, how can I do this please? Hey guys! I've been having trouble with this all day. I'm wanting to display my results in rows. Like, 4 results in 1 row, then another 4, then another 4, etc. like this: IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE IMAGE I'm nto sure how to do that. I want to display pictures. Here is my code for the page: bag.php: Code: [Select] <?php session_start(); include("config536.php"); ?> <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <?php if(!isset($_SESSION['username'])) { echo "<ubar><a href=login.php>Login</a> or <a href=register.php>Register</a></ubar><content><center><font size=6>Error!</font><br><br>You are not Logged In! Please <a href=login.php>Login</a> or <a href=register.php>Register</a> to Continue!</center></content><content><center><font size=6>Inventory</font><br><br></center></content>"; } if(isset($_SESSION['username'])) { echo "<nav>$shownavbar</nav><ubar><img src=/images/layout/player.gif><a href=status.php>$showusername</a>.......................<img src=/images/layout/coin.gif> $scredits</ubar><content><center><font size=6>Inventory</font><br><br>"; $action = $_GET['action']; $gid = $_GET['itemid']; $irow = "SELECT * FROM uitems WHERE username='$showusername'"; $iquery = mysql_query($irow); while($ir = mysql_fetch_array($iquery)) { $uid = $ir['uitemid']; $iid = $ir['theitemid']; $iun = $r['username']; $il = $ir['location']; $tirow = "SELECT * FROM items WHERE itemid='$iid'"; $tiquery = mysql_query($tirow); while($tir = mysql_fetch_array($tiquery)) { $tiid = $tir['itemid']; $tin = $tir['name']; $tiim = $tir['image']; $tid = $tir['description']; $tirr = $tir['rarity']; $tit = $tir['type']; $tiu = $tir['uses']; $tis = $tir['strength']; $tide = $tir['defense']; $tih = $tir['heals']; echo "<img src=/images/items/$tiim><br>$tin<br><br>"; } } } ?> </html>I have no errors, everything works great! It's just I'm not sure how to display them the way I want them. Right now they are displayed like this: IMAGE IMAGE IMAGE IMAGE Any help is greatly appreciated, thank you! Hi there (I'm new at PHP/mysql) I am busy with a project - I maneged to load info into the mysql database and display the results BUT - now I need some Help I can display the result - now I want to have the ability to click on the result and it must open a new page with only the selected result information? Hi, I would like to ask, how to display the while loop result 3 per row with the following code below: $startDate = strtotime($datefrom); I have a classified ad program where I need to export ads (items). This code displays a category, subcategory, ad title, description and price for each ad. I would like to display the category and subcategory followed by the all the ads from within the category and subcategory instead of repeating the category and subcategory for each ad. Any help would be appreciated, thanks in advance! Code: [Select] function getExport() { $this->db->select(" item.id AS item_id, item.title AS item_title, item.description AS item_description, item.price AS item_price, subcategory.subcategory AS subcategory_subcategory, category.category AS category_category, (SELECT IF(item.datestarts IS NULL AND item.dateexpires IS NULL,'PENDING',IF(item.datestarts <= UNIX_TIMESTAMP() AND item.dateexpires >= UNIX_TIMESTAMP(),'ACTIVE',IF(item.dateexpires <= UNIX_TIMESTAMP(),'EXPIRED',''))) FROM item WHERE item.id = item_id) AS item_status"); $this->db->join('subcategory', 'subcategory.id = item.subcategory'); $this->db->join('category','category.id = subcategory.category'); $this->db->join('user','user.id = item.owner'); return($this->db->get($this->table)); I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // This is the main database you connect to. MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); @mysql_select_db( "$dbName") or die( "Unable to select database"); ?> <? //error message (not found message) $XX = "No Record Found"; $query = mysql_query("SELECT * FROM $usertable WHERE $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty I have a database that contains results of fantasy football games. I have a query that returns the results of the games team X played against the other teams in the league. The query works perfect in the database. Results are Quote Opponent Name: America Enforcers Wins Losses Draws 1 1 0 Last Game: Week 2 of 2011: 416.6 - 369.8 the query and the php code cycle thru each team that team X has played and brings up team X's record and the results of the last game played. My problem is that the code stops one team short. So Team X played teams A, B, C, D, E but the code only returns teams A, B, C, D E is left off. I can't for the life of me figure out what silly mistake I made. Code: [Select] <?php include_once('../other/functions.php'); $con = mysql_connect($hostname, $username, $password) OR DIE ('Unable to connect to database! Please try again later.'); $db = mysql_select_db($dbname, $con); $thing = $_GET['thing']; $query = "select selected.teamname AS selected_team, selected_score.score AS selected_score, week.week, year, home_id, ". "target_score.score as target_score, target.teamname as targetname, week.ID ". "from owners as selected ". "JOIN game_scores AS selected_score ON selected.owner_id = selected_score.team_id ". "JOIN game_setup ON game_setup.game_id = selected_score.game_id ". "JOIN game_scores AS target_score ON target_score.game_id = game_setup.game_id AND target_score.team_id != selected_score.team_id ". "JOIN owners AS target ON target.owner_id = target_score.team_id ". "JOIN week ON week.week = game_setup.week ". "WHERE selected.owner_id = $thing ". "and target.active = 1 ". "GROUP BY target.teamname, year, week.ID "; $result = mysql_query($query); $row = mysql_fetch_array($result); $result1 = mysql_query($query); $row1 = mysql_fetch_array($result1); if (!$result) { die('Invalid query: ' . mysql_error()); } $wins=0; $losses=0; $draws=0; $last_target = false; echo '<h2>' . $row1['selected_team'] . ' vs. Active Teams</h2>'; while ($row = mysql_fetch_assoc($result)) { if ($last_target['targetname'] != $row['targetname']) { if ($last_target) { printf(' <table border="1" width="600"> <tr> <th>Opponent Name:</th> <th colspan="2">%s</th> </tr> <tr> <th>Wins</th> <th>Losses</th> <th>Draws</th> </tr> <tr> <td align="center">%d</td> <td align="center">%d</td> <td align="center">%d</td> </tr> <tr> <th>Last Game:</th> <td colspan="2">%s of %s: %.1f - %.1f</td> </tr> </table><br/>', $last_target['targetname'], $wins, $losses, $draws, $last_target['week'], $last_target['year'], $last_target['selected_score'], $last_target['target_score'] ); } $wins = $losses = $draws = 0; } if ($row['selected_score'] < $row['target_score']) ++$losses; elseif ($row['selected_score'] == $row['target_score']) ++$draws; else ++$wins; $last_target = $row; } ?> Any ideas on how to make the magic elvish be good??? Thank you for your time. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=342917.0 Hello, First time posting here, my MYSQL version is 5.1.52 and I have a created a search function to find a user record and if the name is typed correctly the name and details are displayed on the search page, but if the name is typed incorrectly nothing is appearing. Basically I would like to be able to say if no record found and redirect back to the previous page. Code: Code: [Select] <?php add = $_POST['add']; // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Rewards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Add query $sql = mysql_query("UPDATE Rewards SET Rewards = (Rewards + 10) WHERE Name '%$add%'"); // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Update Total Points query $sql = mysql_query("UPDATE UserList SET TotalPoints = (TotalPoints + 10) WHERE Name '%$add%'"); // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); //Search Query $sql = mysql_query("SELECT * FROM UserList WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/><img src="images/line1.jpg" alt="" width="200" height="2" />'; echo '<br/> Username: '.$row['Username']; echo '<br/>'; echo '<br/><img src="images/line2.jpg" alt="" width="200" height="2" />'; echo '<br/> Name: '.$row['Name']; echo '<br/> Year Group: '.$row['YearGroup']; echo '<br/> Form Class: '.$row['FormClass']; echo '<br/>'; echo '<br/><img src="images/line3.jpg" alt="" width="200" height="2" />'; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Rewards"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM Rewards WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Rewards: '.$row['Rewards']; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="Sanctions"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM Sanctions WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Sanctions: '.$row['Sanctions']; } // Database details $host=""; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="UserList"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot SELECT DB"); $sql = mysql_query("SELECT * FROM UserList WHERE Name '%$add%'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Total Points: '.$row['TotalPoints']; echo '<br/>'; echo '<br/><img src="images/line4.jpg" alt="" width="200" height="2" />'; } Any help would be greatly appreciated. Many Thanks P Quinn MOD EDIT: [code] . . . [/code] tags added. Hi, I'm using a form which contains many select boxes. The select boxes looks like this: <select name="locatie" id="locatie"> <option value="" selected>-----</option> <?php require_once ('config.php'); $query = "select ID, locatie from locatie"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$locatie.'</option>'; } ?> </select> <select name="prijsVan" id="prijsVan"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="prijsTot" id="prijsTot"> <option value="" selected>-----</option> <?php $query = "select ID, prijs from prijs"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">€ '.$prijs.'</option>'; } ?> </select> <select name="ligging" id="ligging"> <option value="" selected>-----</option> <?php $query = "select ID, ligging from ligging"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$ligging.'</option>'; } ?> </select> <select name="oppervlakte" id="oppervlakte"> <option value="" selected>-----</option> <?php $query = "select ID, oppervlakte from oppervlakte"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$oppervlakte.' m²</option>'; } ?> </select> <select name="kamers" id="kamers"> <option value="" selected>-----</option> <?php $query = "select ID, kamers from kamers"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$kamers.'</option>'; } ?> </select> <select name="woning" id="woning"> <option value="" selected>-----</option> <?php $query = "select ID, type from woning"; $result = mysql_query ($query); while($row = mysql_fetch_array($result)){ extract($row); echo '<option value="'.$ID.'">'.$type.'</option>'; } ?> </select> <input type="submit" name="submit" value="Zoeken"> To display the result i'm using a PHP processing page which contains the flowing code: <?php ...... ..... $locatie = $_POST['locatie']; $prijsVan = $_POST['prijsVan']; $prijsTot = $_POST['prijsTot']; $ligging = $_POST['ligging']; $oppervlakte = $_POST['oppervlakte']; $kamers = $_POST['kamers']; $woning = $_POST['woning']; $eigenschappen = $_POST['eigenschappen']; // SHOW LOCATIE if($locatie !='' && $prijsVan =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie. "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSVAN if($prijsVan !='' && $locatie !='' && $prijsTot =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW LOCATIE_PRIJSTOT if($prijsTot !='' && $locatie !='' && $prijsVan =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND locatie.ID = '" . $locatie . "' AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS VAN if($prijsVan !='' && $locatie =='' && $prijsTot =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID >= '" . $prijsVan . "' ORDER BY prijs.ID"; } // SHOW PRIJS TOT if($prijsTot !='' && $locatie =='' && $prijsVan =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND prijs.ID <= '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW PRIJS_VAN_PRIJS_TOT if($prijsVan !='' && $prijsTot !='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { $query .= " AND prijs.ID BETWEEN '" . $prijsVan . "' AND '" . $prijsTot . "' ORDER BY prijs.ID"; } // SHOW LIGGING if($ligging !='' && $prijsVan =='' && $prijsTot =='' && $locatie =='' && $oppervlakte =='' && $kamers =='' && $woning =='' && $eigenschappen =='') { $query .= " AND ligging.ID = '" . $ligging. "' ORDER BY prijs.ID"; } ...................... and so on......... // Error: indien geen keuze gemaakt show deze error if($prijsVan =='' && $prijsTot =='' && $locatie =='' && $woning =='' && $ligging =='' && $oppervlakte =='' && $kamers =='' && $eigenschappen =='') { ?> <center><font color="#666"> <?php postError(); ?></font></center><?php } else{ //Execute query $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['image_id'] ; echo $row['locatie'] ; echo $row['prijs']; echo $row['type']; echo $row['kamers']; echo $row['oppervlakte'] . ' m²'; echo $row['ligging']; echo $row['eigenschappen']; } } mysql_close($con); ?> As you see i have to use many IF condition to display the result of every select combinations. Is there any way to do it in better way and using less coding? Thanks. |