PHP - Why Do I Not Get Any Results Returned From This Code?
Similar TutorialsHi guys, I am working with an old script at the moment, there is one page which just will not populate the table results. I have tried running multiple debugging commands but the only one it flags is the line displaying Quote last; saying it's not a used function. If I comment out this line, no errors are produced but the results do not enter the table. Can anyone shed some light on this please, I've spent hours and hours and banging my head against a brick wall would probably be more constructive right now. Many thanks indeed for any help or advice. <?php mysql_connect("localhost", "$db_user","$db_upwd") or die ("Error - Could not connect: " . mysql_error()); mysql_select_db("$database"); $query="select host,count(*) from badc_mis_prog group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); $count=0; $hosts=array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); array_push($hosts, $html_hlname,$row[1],0); $count++; } $query="select host,count(*) from badc_mis_prog where reported=1 group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); for ($i=0; $i<($count*3); $i+=3) { if ($hosts[$i] == $html_hlname) { $hosts[($i+2)]=$row[1]; last; } } } for ($i=0 ; $i<(($count-1)*3); $i+=3){ for ($j=$i+3 ; $j<($count*3); $j+=3){ if ($hosts[($i+1)] < $hosts[($j+1)]){ $temp=array(); $temp[0]=$hosts[$i]; $temp[1]=$hosts[($i+1)]; $temp[2]=$hosts[($i+2)]; $hosts[$i]=$hosts[$j]; $hosts[($i+1)]=$hosts[($j+1)]; $hosts[($i+2)]=$hosts[($j+2)]; $hosts[$j]=$temp[0]; $hosts[($j+1)]=$temp[1]; $hosts[($j+2)]=$temp[2]; } } } print "<br><br><br><center><table border=\"1\">\n"; print "<tr><td>Host Name</td><td>Hosted</td><td>Reported</td><td>Ratio H/R</td></tr>\n"; for ($i=0; $i<($count*3); $i+=3) { if ($hosts[($i+1)]<15){ break;} printf ("<tr><td> %s </td><td> %d </td><td> %d </td><td>%.1f %%</td></tr>\n",$hosts[$i],$hosts[($i+1)],$hosts[($i+2)],(($hosts[($i+2)]/$hosts[($i+1)])*100)); } print "</table></center>\n"; ?> Greetings! This n00b has a "search engine" dedicated to extracting relevant information from log files. It works by parsing preset fields in the log filename. I'd like to have some notification when the search returns no rows as I am planning to add more search options. Here's my code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> <title>LogFile Search</title> <style type="text/css"> <<irrelevant stuff removed>> </style> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" language="javascript" src="js/UI.js"></script> </head> <body> <h3 id="myh3">Log File Search</h3><h5>Version 1.0.1</h5> <h4 id="myh4"><ul><li> <<irrelevant stuff removed>> </li></ul></h4> <form method="post" name="LogFile_Search" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <table id="mytable"> <tbody> <tr> <td id="mytd">Result(P|F|N): <input type="text" id="Result_PFN" name="Result_PFN" size="31"/></td> <td id="mytd">Script Version: <input type="text" id="ScriptVersion" name="ScriptVersion" size="31"/></td> </tr> </tbody> </table> <br> <input type="submit" value="Search" onclick="doForm();"> <input type="button" value="Reset" onclick="resetForm();"> </form> <div id="searchResult"> <?php /* Where the logs files are dropped by external process. */ $mydir = $_SERVER['DOCUMENT_ROOT'] . "/LogFile_Search/LogFiles"; /* Handle to directory. */ $dir = opendir($mydir); /* Form variables. */ $Result_PFN = $_POST['Result_PFN']; $ScriptVersion = $_POST['ScriptVersion']; /* Test each field -- triggers JS alert if all are empty. */ if (!empty($Result_PFN)) { doResult_PFN(); } elseif (!empty($ScriptVersion)) { doScriptVersion(); } /* Function for Search on Script version in logfile contents. */ function doScriptVersion() { global $dir; global $mydir; global $ScriptVersion; echo '<table id=\'mytable\'><tbody><tr><td id=\'mytd\'>Log File Name.</td></tr>'; //grabs all log files matching the script version number that's input in the form. $cmd = "find " . $mydir . " -type f -print0 | xargs -0 grep -e 'Test_Version=" . $ScriptVersion . "'"; exec($cmd, $output); //Sort the array using a case insensitive "natural order" algorithm. natcasesort($output); if (count($output) > 0) { foreach ($output as $v) { //Display file name without full path as URL. echo '<tr><td><a href="' . basename($mydir) . '/' . array_pop(explode("/", array_shift(explode(":", $v)))) . '" target="_blank">' . array_pop(explode("/", array_shift(explode(":", $v)))) . '</a></td></tr>'; } } else { echo "<html><body style=\"background-color:#0080c0\"> <script type=\"text/javascript\" language=\"javascript\">alert( 'Nothing found' + '.');</script> </body></html>"; } closedir($dir); echo "</table></body>"; } /* Function for Search on Result marker in file name. */ function doResult_PFN() { global $dir; global $mydir; global $Result_PFN; echo '<table id=\'mytable\'><tbody><tr><td id=\'mytd\'>Log File Name.</td></tr>'; if ($dir) { //List files in directory while (($file = readdir($dir)) !== false) //Ignores OS stuff. if ($file != "." && $file != "..") { //Pattern match for result. if (preg_match("/~(P|F|N)*" . $Result_PFN . "~/i", $file)) { //Sort the array using a case insensitive "natural order" algorithm. natcasesort($file); echo '<tr><td><a href="' . basename($mydir) . '/' . $file . '" target="_blank">' . $file . '</a></td></tr>'; } } else { echo "<html><body style=\"background-color:#0080c0\"> <script type=\"text/javascript\" language=\"javascript\">alert( 'Nothing found' + '.');</script> </body></html>"; } closedir($dir); } echo "</table></body>"; } ?> </div> </body> </html> When doResult_PFN() returns no result, the ELSE portion is never evaluated and no notification is sent to the user. However, I have no problem with doScriptVersion(): it returns an alert. What am I missing? Thanks, Al. Hello. I am interested in taking a result returned from a database and having it displayed in a certain way/style on the user's screen; For example, the user enters text into a field and hits "submit" - the data is saved in the database then displayed to the user (This part I have working just fine so far due to help I received here.) My question is if I would like to, for example, have said text not simply dumped to the top of the screen, inline, but nicely formatted in a boxed, text area, I assume I will use HTML/CSS, and I was wondering if anyone had any good links/tutorials regarding this topic so I may look further into it (my search thus far has not turned up the correct topic or results). Thank-you in advance for any assistance. ~Matty Search not functioning. The drop down box to search on Club_Name and Email is blank, clicking search results unchanged ... all suggestions appreciated ... newbie at php. Thanks. <!-- Code below is not functional, trying to query search results, search box with drop down box for two fields--> <table width="50%"> <tr> <td height="30" align="left" bgcolor="#FFFFFF" class="form1" > {$letter_links} </td> <td height="30" align="right" bgcolor="#FFFFFF" class="form1" > <input type=hidden name="sorter" value="{$sorter}"> <table><tr> <form name="search_form" action="{$form.action}" method="post"> <td class="form1" ><input type="text" name="search" value="{$search}"></td> <td class="form1" ><select name="s_type" style=""> {section name=s loop=$types} <option value="{$smarty.section.s.index_next}" {if $types .sel}selected{/if}>{$types .value}</option> {/section} </select></td> <td class="form1"><input type="button" value="{$button.search}" class="button" onclick="javascript: document.search_form.submit();" name="search_submit"></td> </form> </tr></table> </td> </tr> </table> <!-- Code below successfully displays query results --> <form method="post" action="{$file_name}?sel=approve" enctype="multipart/form-data" name="form1" onsubmit="foo(); return false;"> <table cellspacing="2" cellpadding="10" border="1"> <tr align="center"><td>Num</td><td>Club Name</td><td>Login</td><td>Country</td><td>Region</td><td>City</td><td>Address</td><td>Web site</td><td>Email</td><td>Contact Name</td><td>Contact Phone</td><td>Swinging</td><td>Alcohol</td><td>Food</td><td>Entertainment</td><td>Fees</td><td>Approved/<br/>Rejected</td><td>Actions</td></tr> {foreach item=item from=$contest key=key name=foo} <tr align="center"><td><input type="hidden" name="all_approves[{$item.id}]" value="{$item.id}"/>{$key+1}</td><td>{$item.name}</td><td>{$item.login}</td><td>{$item.country_name}</td><td>{$item.region_name}</td><td>{$item.city_name}</td><td>{$item.address}</td><td>{$item.web_site}</td><td>{$item.email}</td><td>{$item.contact_name}</td><td>{$item.contact_phone}</td> <td> {math equation="x - 1" x=$item.swinging assign=index_pos} {$xml_swing[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.alcohol assign=index_pos}{$xml_alco[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.foot assign=index_pos}{$xml_foot[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.entertainment assign=index_pos}{$xml_entertainment[$index_pos].value}</td> <td>{math equation="x - 1" x=$item.fees assign=index_pos}{$xml_fees[$index_pos].value}</td><td> <span> {if $item.is_approved eq '1'} Approved {else} Rejected {/if}</span></td><td align="center"><a href="{$file_name}?sel=edit&id_content={$item.id}">[ Edit ]</a><br/><a href="{$file_name}?sel=delete&id_content={$item.id}">[ Delete ]</a><br/><a href="{$file_name}?sel=approve&id_content={$item.id}">[ Approve ]</a><br/><a href="{$file_name}?sel=reject&id_content={$item.id}">[ Reject ]</a></tr> {/foreach} </table> </form> I am looking to accomplish the following but have been hitting a brick wall: * User enters a single keyword into a text field, and conducts a search keyword search. * The results are pulled from the campusbooks.com API(API docs attached) * result are then output in <div> class and includes all the book details and its corresponding url./img etc I'm trying to simplify this process but I continue to receive syntax errors. A step by step practical explanation would do me justice! I've had a bit of a search around to see if this is possible but have yet to find something. I'm looking to be able to offset the results from opendir or similar function without returning all the files/folders. In other words i'd like to display the file/folder results over multiple pages when there are a lot of files/folders to display. Is this at all possible? I'm hoping this is a simple question. When I use the code below, my twitter search query appears in BOLD within the returned results. I would like to style the search term differently. I can use CSS to style the avatar, author, and other information within the returned results etc, but I can't figure out how to style the search term ($q) within the returned twitter information. Any help would be much appreciated. <?php class twitter_class { function twitter_class() { $this->realNamePattern = '/\((.*?)\)/'; $this->searchURL = 'http://search.twitter.com/search.atom?lang=en&q='; $this->intervalNames = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year'); $this->intervalSeconds = array( 1, 60, 3600, 86400, 604800, 2630880, 31570560); $this->badWords = array('somebadword', 'anotherbadword'); } function getTweets($q, $limit=15) { $output = ''; // get the search result $ch= curl_init($this->searchURL . urlencode($q)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $response = curl_exec($ch); if ($response !== FALSE) { $xml = simplexml_load_string($response); $output = ''; $tweets = 0; for($i=0; $i<count($xml->entry); $i++) { $crtEntry = $xml->entry[$i]; $account = $crtEntry->author->uri; $image = $crtEntry->link[1]->attributes()->href; $tweet = $crtEntry->content; // skip tweets containing banned words $foundBadWord = false; foreach ($this->badWords as $badWord) { if(stristr($tweet, $badWord) !== FALSE) { $foundBadWord = true; break; } } $tweet = str_replace('<a href=', '<a target="_blank" href=', $tweet); // skip this tweet containing a banned word if ($foundBadWord) continue; // don't process any more tweets if at the limit if ($tweets==$limit) break; $tweets++; // name is in this format "acountname (Real Name)" preg_match($this->realNamePattern, $crtEntry->author->name, $matches); $name = $matches[1]; // get the time passed between now and the time of tweet, don't allow for negative // (future) values that may have occured if server time is wrong $time = 'just now'; $secondsPassed = time() - strtotime($crtEntry->published); if ($secondsPassed>0) { // see what interval are we in for($j = count($this->intervalSeconds)-1; ($j >= 0); $j--) { $crtIntervalName = $this->intervalNames[$j]; $crtInterval = $this->intervalSeconds[$j]; if ($secondsPassed >= $crtInterval) { $value = floor($secondsPassed / $crtInterval); if ($value > 1) $crtIntervalName .= 's'; $time = $value . ' ' . $crtIntervalName . ' ago'; break; } } } $output .= ' <div class="tweet"> <div class="avatar"> <a href="' . $account . '" target="_blank"><img src="' . $image .'"></a> </div> <div class="message"> <span class="author"><a href="' . $account . '" target="_blank">' . $name . '</a></span>: ' . $tweet . '<span class="time"> - ' . $time . '</span> </div> </div>'; } } else $output = '<div class="tweet"><span class="error">' . curl_error($ch) . '</span></div>'; curl_close($ch); return $output; } } ?> The HTML I have been using with this code is here Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Twitter</title> </head> <body> <?php require('twitter.class.php'); $twitter = new twitter_class(); echo $twitter->getTweets('example search term', 10); ?> </body> </html> This is not my code. It is from a tutorial that can be accessed from here >> http://www.richnetapps.com/php-twitter-search-parser/ here is my code... please help <form method="get" action="shit3.php"> <input maxlength="50" size="50" type="text" name="q"> <input type="submit" value="SEARCH"> </form> <?php if (@$_GET['q']) { $var = $_GET['q'] ; $trimmed = trim($var); $limit=1; if ($trimmed == "") { echo "Please enter a search..."; exit; } if (!isset($var)) { echo "Container not found!"; exit; } mysql_connect("localhost", "xxx", "yyy") or die(mysql_error()); mysql_query("SET NAMES 'cp1251'"); mysql_select_db("agaexpor_container") or die("Unable to select database"); //select which database we're using $query = "select * from containertracking where vin like \"%$trimmed%\" order by vin"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if (empty($s)) { $s=0; } $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); $count = 1 + $s ; while ($row= mysql_fetch_array($result)) { $vin = $row["vin"]; $container = $row["container"]; echo "$count.) VIN: $vin <br />"; echo "container is: $container <br />"; $count++ ; } } ?> Hello, I'm new on this forum and i have not seen the rules to post a code, so i will try to explain my best : I have learned the basics of php during the past few days and i have a php code that is supposed to read parameters in several fields of a Mysql database and to return those parameters as variables in an array. (well that's how i understand it... please correct me if i'm wrong) So here the code and the part that doesn't seem to work properly (colored in red) : //I have changed the following values which are confidential... $DBName = "MyDatabase"; $DBHostName = "MyMysqlServer"; $DBUserName = "MyUsername"; $DBPassword = "MyPassword"; $Table = "MyTable"; //The fields which are in MyTable : // MemberID SMALLINT // MemberName VARCHAR(20) // MemberPassword VARCHAR(20) // MemberEmailAddress VARCHAR(50) // MemberDateTimeInscription VARCHAR(19) //Reading member parameters echo"<br>Reading the parameters of a member."; echo"<br>Defining the parameters of the member to read."; $CurrentName = "Ashley"; $CurrentPassword = "65hl3y"; $CurrentEmailAddress = "Ashley@HisDomain.com"; echo"<br>Trying to start a connection with the Mysql server."; mysql_connect($DBHostName,$DBUserName,$DBPassword) OR DIE(mysql_error()); echo"<br>Selecting the table."; mysql_select_db($DBName) OR DIE(mysql_error()); echo"<br>Searching for the fields corresponding to the CurrentName."; $Query = "SELECT * FROM ".$Table." WHERE MemberName = '".$CurrentName."'"; $Result = mysql_query($Query) or die(mysql_error()); echo"<br>Returning the parameters stored in the fields."; while($Row = mysql_fetch_array($Result,MYSQL_ASSOC)){ /////This is the start of the part that does not seem to work properly. $MemberId = $row["MemberId"]; $MemberName = $row["MemberName"]; $MemberPassword = $row["MemberPassword"]; $MemberEmailAddress = $row["MemberEmailAddress"]; $MemberDateTimeInscription = $row["MemberDateTimeInscription"]; echo"<br>MemberId : ".$MemberId; echo"<br>MemberName : ".$MemberName; echo"<br>MemberPassword : ".$MemberPassword; echo"<br>MemberEmailAddress : ".$MemberEmailAddress; echo"<br>MemberDateTimeInscription : ".$MemberDateTimeInscription; /////This is the end of the part that does not seem to work properly. } echo"<br>Ending the connection with the Mysql server."; mysql_close(); All of echo are here for debug, i'm a beginner with php. This is what the php page shows : Reading the parameters of a member. Defining the parameters of the member to read. Trying to start a connection with the Mysql server. Selecting the table. Searching for the fields corresponding to the CurrentName. Returning the parameters stored in the fields. MemberId : MemberName : MemberPassword : MemberEmailAddress : MemberDateTimeInscription : Ending the connection with the Mysql server. I don't understand why the variables $MemberId, $MemberName, $MemberPassword, $MemberEmailAddress, $MemberDateTimeInscription are empty. Your advices are welcome, Thanks, Ok so I followed Buddski's advice to use MIME for the attatchment. (thanks for the help by the way, definitely headed in the right direction now.... i think...) The image now successfully uploads to temp_folder on submit, the email is then delivered with correct text variables (name, phone, address etc.). However, instead of their being an image included - there is just raw code. If anyone could help with the final fix you may just save my sanity! Thanks. Code: [Select] <?php ini_set("sendmail_from", "darren@mywebsite.co.uk"); ini_set("SMTP", "smtp.myhosts.co.uk"); // Subject and Email Destinations // $emailSubject = 'Work Email!'; $webMaster = 'darren@mywebsite.co.uk'; // Gathering Data Variables // $name = trim($_POST['name']); // create a unique boundary string // $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the headers for a file attachment // $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // Add a multipart boundary above the plain message // $message ="This is a multi-part message in MIME format.\n\n"; $message.="--{$mime_boundary}\n"; $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message.="Content-Transfer-Encoding: 7bit\n\n"; $message.= "Name: ".$name."\n"; //The file type of the attachment // $file_type = 'text/csv'; // The place the files will be uploaded to (currently a 'files' directory) // $upload_path = './uploads/'; // Get the name of the file (including file extension) // $filename = $_FILES['userfile']['name']; // Get the extension from the filename // $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Configuration of File Uploaded // $allowed_filetypes = array('.jpg','.JPEG','.jpeg','.gif','.bmp','.png'); $max_filesize = 2000000; (move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)); //This attatches the image file to the email // $message .= chunk_split(base64_encode(file_get_contents($upload_path . $filename))); // Send the Email with the attatchment. $success = mail($webMaster, $emailSubject, $message, $headers, "-fdarren@dsinteriorsltd.co.uk"); ?> >>>is returning this to my email... Code: [Select] MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="==Multipart_Boundary_x9cbb390d8be528476c5423025ed1e4ccx" This is a multi-part message in MIME format. --==Multipart_Boundary_x9cbb390d8be528476c5423025ed1e4ccx Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Name: darren /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEB........................................................... ..........this code goes on like this for ages. I'm working on this database that was built by somebody else, and I'm having issues with. I'm attaching a photo of the database. The problem I'm having is that even when I hard-code variables in the statement, it still brings back "Sorry, but we can not find an entry to match your query" Is there something that I'm not seeing, or something that I'm doing wrong here? You can clearly see in the photo that I'm trying to grab the info with the id_pk 300000. Code: [Select] <?php //$search = $_POST['search']; //$search = '300000'; $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = '300000'"); while($result = mysql_fetch_array( $data )) { $name = $result['page_name']; $id = $result['id_pk']; $page = $result['html']; $cat = $result['category']; $dir = $result['directory']; echo "ID: " .$id ."<br>Page: ". $name ."<br>HTML: ". $page ."<br>Category: ". $cat ."<br>Directory: ". $dir ."<br />"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } ?> Thanks in advance [attachment deleted by admin] i basically have a php search form on a property website, and depending on what area/type of property/number of bedrooms and price range the search form should bring up results based on that. at the moment it just bring up everything. how would i make it bring up the correct results depending on the search made? here my php code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Mumtaz Properties</title> <link rel="stylesheet" href="cutouts/style.css"/> </head> <body> <!--Main Div Tag--> <div id="wrapper"> <div id="header"> <div id="logo"><a href="index.html"><img src="cutouts/Homepage/logo.png" alt=""/></a></div> </div> <div id="navigation"> <a id="Home" href="index.html" title="home"><span>home</span></a> <a id="Sale" href="forsale.html" title="for sale"><span>for sale</span></a> <a id="Rent" href="forrent.html" title="for rent"><span>for rent</span></a> <a id="Contact" href="contact.html" title="contact us"><span>contact us</span></a> </div> <div id="main"> <div id="results"><img src="cutouts/Homepage/results.png"></div> <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use // Query database $result = mysql_query("SELECT * FROM Properties"); if (!$result) { echo "Error running query:<br>"; trigger_error(mysql_error()); } elseif(!mysql_num_rows($result)) { // no records found by query. echo "No records found"; } else { $i = 0; echo '<div style="font-family:helvetica; font-size:14px; padding-left:15px; padding-top:20px;">'; while($row = mysql_fetch_array($result)) { // Loop through results $i++; echo '<img class="image1" src="'. $row['images'] .'" />'; //image echo "<span style=\"color:#63be21;\">Displaying record $i<br>\n<br></span>"; echo "<b>Location:</b> ". $row['Location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo "<b>Property Type:</b> ". $row['Property_type'] . "<br>\n"; // as above echo "<b>Bedrooms:</b> ". $row['Number_of_bedrooms'] . "<br>\n"; // .. echo "<b>Purchase Type:</b> ". $row['Purchase_type'] . "<br>\n"; // .. echo "<b>Price:</b> ". $row['Price_range'] . "<br>\n"; // .. } echo '</div>'; } mysql_close($con); // Close the connection to the database after results, not before. ?> </div> </div> </body> </html> Would like to thank you in advance. Hello, Here's the weird thing, some of the pages shows the results, and some pages just won't show results at all, and I'm not getting any errors here is the one that doesn't Code: [Select] <? function display_mptt($user) { global $db; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id='25'"; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Users List</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE 'left' BETWEEN '".$row2['left']."' AND '".$row2['right']."' ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)or die(mysql_error())) { // only check stack if there is one $count = mysql_num_rows($result); if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $var3 = '10'; echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> </tr>"; echo "<tr><td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['title'] ." </td>"; echo "</tr>"; echo "</table>"; $right[] = $row['right']; } } display_mptt(1); ?> and here is the page that does Code: [Select] <? function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title echo str_repeat(' ',count($right)).$row['title']."<br>"; // add this node to the stack $right[] = $row['right']; } } display_mptt(1); ?> This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330251.0 Hey guys, Having a slight problem with part of the code in my index.php file Code: [Select] mysql_select_db('db_name', $con); $result = mysql_query("SELECT * FROM spy ORDER BY id desc limit 25"); $resulto = mysql_query("SELECT * FROM spy ORDER BY id desc"); $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) { ?> <div class="contentDiv">Someone is looking at <?=$row[title];?> Stats for "<a href="/<?=$row[type];?>/<?=$row[code];?>/<?=$row[city];?>"><?=$row[code];?> <?=$row[city];?></a>"</div> <?}?> </div> <div id="login"></div> <? include("footer.php"); ?> </div> </body> </html> I'm getting the following error when viewing the file Code: [Select] Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 70 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ~path to file/index.php on line 71 where lines 70 and 71 are $count = mysql_num_rows($resulto); while($row = mysql_fetch_array($result)) Any ideas on how to fix this? hi guys, i just finished highschool starting to do webdesign at uni, and for one of my major project i want to make a search engine as simple as google that searches for example 10 websites and with the keyword given it brings out the results. im doing a website on jetski sales results so if someone want to buy a jetski they come to this website and just choose the choose one from those 10 website without going to them individually. so it brings out all search resuts in a nice results format, and when you click on each results it take you to the website but i wanna be able to show their photo and price so just like brings their results into your site but combing 10 website results. and i need to have an advance search option where they can search year price age of jetski, and all these variables are also in the 10 websites that im getting the results from. i have been doing some searching and i cant get my head around i need some help LOL i dont wanna fail... cheers guys am total newbie to programming, apart from knowing SQL, the thing is i have been given a MYSQL database containing various information about kids diseases and a web interface written in php to create reports from the database that can be accessed via the interface. there are almost 25 different variables that need to be computed in the report, i have written sql queries to compute all these values, but i don't know anything about PHP, if i have all these queries isn't there a way for me to combine all these sql queries to be display results on a webpage and come up with this report without writing PHP code? Thanks for your help very sorry if this is too basic i have an admin page that lists all the rows from a table. One of the fields is generated using FCKEditor, so the field has HTML Code in it. I would like to only show the first 100 or so chars of the field, but if the 100 chars ends in the middle of HTML code, specifically in this case <a href>, it cuts off, and creates "havoc" in my page. Is there a way to avoid this by seeing that the 100 char is in the middle of an <a href> tag (or any tag for that matter? Here is what the generated html can look like :: <td class="tdresults">We are very excited to offer three great events at the <a href="http://www.mylongwebsite.c</td> <td class="tdresults">next field data</td> Thank you in advance. Pete Hi, The code for displaying a results set in multiple columns (http://www.phpfreaks.com/forums/index.php?topic=95426.0) works really well and displays 1 2 3 4 5 6 7 8 Does anyone know how to change so it displays as 1 3 5 7 2 4 6 8 Any help would be greatly appreciated thanks a This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=355144.0 |