PHP - Moved: Display Result Of Last 30 Days
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=342917.0 Similar TutorialsThis topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=320501.0 Hello, I am trying to display rainfall totals for the year so far in a table with months going across and days going down. Like so: -- Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1 2 3 4 5 6 7 8 etc And then have the rainfall totals for each day in the table, I am quite experienced with PHP however I cant work out how I would do this The data is stored in a mysql table called "wx_daily", and the rainfall column is called" RainTotal". The dates are stored in the "Date" column in mysql Date format. Im using the following mysql query: SELECT * FROM wx_daily WHERE YEAR(Date) = '2011' ORDER BY Date Asc Thanks, Mark Hi guys. So I have a little coding down but I am stuck on this problem: /* Using only a array and a foreach loop, write a program that prints the days of the week *\ $days = array { 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', }; //This is where I need help with the code echo "$day \r\n"; ?> Thanks in advance! 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 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'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 } ?> 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)); 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! 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. 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? 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? 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. 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 have a job listing website which displays the closing date of applications using: $expired_date (This displays a date such as 31st December 2019) I am trying to show a countdown/number of days left until the closing date. I have put this together, but I can't get it to show the number of days. <?php $expired_date = get_post_meta( $post->ID, '_job_expires', true ); $hide_expiration = get_post_meta( $post->ID, '_hide_expiration', true ); if(empty($hide_expiration )) { if(!empty($expired_date)) { ?> <span><?php echo date_i18n( get_option( 'date_format' ), strtotime( get_post_meta( $post->ID, '_job_expires', true ) ) ) ?></span> <?php $datetime1 = new DateTime($expired_date); $datetime2 = date('d'); $interval = $datetime1->diff($datetime2); echo $interval->d; ?> <?php } } ?> Can anyone help me with what I have wrong? Many thanks 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. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=353485.0 Hello, I have been developing a website that needs to display products online, I was originally going to hand-write the PHP code but I thought it would be more beneficial to make it database orientated as new products can easily be added and a search function becomes possible. I have it working so far so good, but the last part I can't seem to get working. I have it so all the products that have the desired category are displayed, but I want a more detailed analysis of the product to appear when the image is clicked, which at the moment, displays a blank page. http://www.webwib.co...?p=floorpuzzles - this is the hand coded version that demonstrates how I want it to work. http://www.webwib.co...hp?floorpuzzles - this is the db version so far, it works how it is intended to apart from the last stage, which returns as a blank page rather than a dedicated page for the selected product. Here is my code, the third segment beginning with "if(isset($_GET['$ID'])){", is my attempt at the final stage. <?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); if(isset($_GET['floorpuzzles'])){ echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID#productspage\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['anothercategory'])){ $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . AnotherCategory . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<h1>Our Floor Puzzles</h1>"; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?$ID0#productspage\"><img src=\"images/products/catalogue//$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } } if(isset($_GET['$ID'])){ $sql="SELECT ID, Name, Tags, Description, Peices, Size, Barcode, Category FROM products WHERE ID LIKE '%" . $ID . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode $Barcode</p>"; echo "</div>"; } } include("footer.php"); ?>Thank you in advance for any assistance given. I am building online dictionary with php. The following code allows the user to search a word and display the definition results from the database. The problem is the user has to input the identical words only. If the words are not exactly similar to the database words it returns error message. But in this case I need it to give a suggestion along with the error message based on the few beginning words of the submitted word. eg. if the user type a word "suggestion", and the word "suggestion" is not available in the database .... instead of just the error message to also search and include other stored data closer to the submitted word ... like "TRY the word SUGGEST". can any one help me on this please. Thank you in advance. here is the code Code: [Select] <?php $script = $_SERVER['PHP_SELF']; if(isset($_POST['sbm']) && isset($_POST['word']) ) { submited(); } else { show_form(); } function show_form() { ?> <p><center> Type <span style='font-weight:bold;'>ENGLISH</span> word Only! <span style='font-weight:bold;'>SPELL IT CORRECTLY!!!.</span></center></P> <p><center>Search</center></p> <center><form name=frm method=POST action="<?php echo $script ?>"> <p><input type=text name="word"><br /></p> <p><input type=submit name="sbm" value="Submit"> </form> </center></p> <?php } function submited() { require("dbconn.inc"); $word=$_POST['word']; $sql="select * from words where eng like '".mysql_real_escape_string($word)."'"; $result=mysql_query($sql,$link); // I assume $link is defined in dbconn.inc if(@mysql_num_rows($result)!=0) { $rows=mysql_fetch_array($result); $am=$rows["am"]; echo("<center>The Word <h1><b>$word</b></h1> in Am is : <h1><b>$am </b></h1><br></center>"); } else { echo("<center><span style='font-weight:bold;color:#FF0000;'>Could not find it! Check the spelling and try again !!</span></center>"); } // The connection will close automatically since // this is near the end of the script. mysql_close($link); show_form(); } ?> |