PHP - How Can I Display Results Of An Array In Individual Rows.
I've got my code working OK in that the correct results are drawn from the database. What I have here in the code is an array consisting of an image, accompanied by its title and thirdly a link to activate a quiz associated with the image. Everything works fine, except because the page is dynamic, I always have an unknown number of sets of data (image, title and link) which I want to display so that each set of data takes up a new row.
The code I have here, while displaying the correct data, places all of the results into the same row. Any suggestions are most welcome. Code: [Select] <?php // Query the database $query1 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query2 = mysql_query("SELECT url_small FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); $query3 = mysql_query("SELECT title FROM topics WHERE managerId='".$managerId."' AND egroup1='"."1"."' ORDER BY title ASC"); while($row1 = mysql_fetch_array($query3)) { $linkname .= $row1['title']."<br />\n"; } ?> <table> <tr> <td> <?php while ($row2 = mysql_fetch_array($query2)) { $thumbnail.= $row2['url_small']; echo "<img src='wood_tool_images/{$row2['url_small']}' alt='' /><br />\n"; } ?> </td> <td height="200"> <?php echo $linkname ?> </td> <td> <?php while ($row1 = mysql_fetch_array($query1)) { $quizname.= $row1['title']; echo "<a href='../{$row1['title']} Safety Quiz/{$row1['title']} Safety Quiz.php'>Take This Quiz</a><br />\n"; } ?> </td> </tr> </table> Similar TutorialsHi Guys! Trying to display data in 3 rows horizontally and 25 vertiacally Code: [Select] // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(biddersId)'] ." bidders logged."; echo "<br />"; } $query = "SELECT * FROM bidders ORDER BY biddersId"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Bidders</th>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo"<font face= \"calibri\" size=\"3\">"; echo $row['biddersId']; echo "</br>"; echo "</td><td>"; } echo "</table>"; ?> I am having problems displaying individual data I am using $filename[0] to display the first data, any ideas where i am going wrong. <?php $active_keys = array(); foreach($_POST['img'] as $key => $filename) { if(!empty($filename)) { $active_keys[] = $key; } echo "". $filename[1]; } ?> I figure I'd use array_chunk to divide my array by 5's, but how can I get each set of five to be enclosed in div tags. My array is a list of images in a directory which I need inserted into a format like the example code on this page. http://flowplayer.org/tools/demos/scrollable/index.html. Thanks for any help. I have a database query set up that returns an array. I then cycle through the rows in a foreach statement that wraps each value in a <td> tag to output it to a table. It works really great, but now I need to access two of the values and add some info to them. The first field returned is an image filename and I want to wrap it in an image tag that also concatenates the image path location to the value. All the images are stored in the same location, so basically I want to take the first value form the array and add the path to where the images are and wrap the whole thing in an <img> tag. The other field I need to modify is the last value in the array which is actually an email address. For that field I want to make them an active email link so I need to wrap an <a>href=mailto: </a> tag around the value. How could I modify this code so I could add the necessary tags to these elements of the array? Here is the code I am running: Code: [Select] $query = "Select member_image as 'Image', member_name as 'Name', city as 'City', phone as 'Phone', email as 'Email' FROM directory"; //connect to database $conn=db_connect(); //call function do_query to run the query and output the table do_query($conn, $querey); The functions called are as follows: Code: [Select] function db_connect() { $conn = new mysqli("localhost", "username", "password", "databasename"); } function do_query($conn, $query); { $result = mysqli_query($conn, $query); WHILE ($row = mysqli_fetch_assoc($result)) { If (!$heading) //only do if header row hasn't been output yet { $heading = TRUE; //so we only do it once echo "<table>\n<tr<>\n"; foreach ($row as $key => $val) { echo "<th>$key</th>"; } echo "</tr>\n"; } echo "<tr>"; foreach ($row as $val) { echo "<td> $val </td>"; } echo "</tr>\n"; } //close the while echo "</table>\n"; } Hi all, I need your help as I have got a problem with display the 50 rows in the search results. I want to limit 50 rows in per page and if I have less than 50 rows like 21 rows in the page 2 then display the 21 rows. I have got a problem with the limit, because when I tried to use `LIMIT 0, 50`, it will display total 71 rows which I only want to display no more than 50 in per page. Here is what I have tried: $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]);
$search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]);
Here is the full code:
<?php // Initialize the session session_start(); //Connect to the database require_once('config.php'); $searchemail = '%' . 'gmail.com' . '%'; $searchsubject = '%' . 'gmail.com' . '%'; $searchmessage = '%' . 'gmail.com' . '%'; $mailbox = $link->prepare("SHOW TABLES"); $mailbox->execute(); $folders = array(); $total = 0; $total_rows = 0; $i = 0; while ($folder = $mailbox->fetch(PDO::FETCH_NUM)) { $folder = $folder[0]; if (strpos($folder, 'users') !== false) { $folder = str_replace('users', '', $folder); } else { $folders[$i] = $folder; } $i++; } foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { $total += $search_mailbox->rowCount(); } } $page = 1; $limit = 50; //$per_page = 50; //$pages = ceil($total / $per_page); $offset = ($page - 1) * $limit; foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { foreach($search_mailbox->fetchAll() as $k => $row) { $email_number = $row['id']; $search_from = $row['from_email']; $search_subject = $row['subject']; $total_rows++; echo $search_subject . '.........................' . $total_rows; echo "<br>"; } } } ?> I am unable to fetch the first 50 rows in the page 1 and I am also unable to fetch the 21 rows in the page 2. What I am trying to achieve is when I am in page 1, I want to display the first 50 rows, then in the page 2 if I have another 50 rows then display the 50 rows, but if I have less than 50 rows like 21 rows then display the 21 rows. Can you please show me an example how I can start with first 50 rows when I am in the page 1 then in page 2 display 21 rows to make in total 71 rows? Any advice would be much appreicated. Thanks in advance. Alright, I need to find a way to display the top ten duplicated rows for a table in my database. I have tried multiple methods but I have failed. Can you please assist me with this problem. I currently run a query in phpmyadmin to get the result, but i cant figure out how to properly code the php script. hello, all: I'm a newbie, and been trying to work out a way so that the results from an array (or mysql recordset for that matter), are nicely aranged in a table. I want them to show in a grid-like manner, with rows and columns added according to number of "items". I worked out this small code snippet, with a sample array, and for the life of me, cant figure out how to make it so it automatically "breaks" columns at 5 and start new row. I got it to show me right number of rows, but then it repeats all 10 names within them, as opposed to just showing 5 names in each row... Appreciate the help... Code: [Select] <?php $names = array('Charles','Henry','Manny','Philip','Rose','Evelyn','Peter','Julia','Cary','Sophia'); $numberColumns = 5; $numberNames = count($names); $numberRows = ceil($numberNames / $numberColumns); echo "<table border='1' width='400' cellspacing='0' cellpadding='0'>"; for ($i=1; $i<=$numberRows; $i++) { echo "<tr>"; foreach ($names as $name) { echo "<td>" . $name . "</td>"; } echo "</tr>"; } echo "</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! <?php require_once('upper.php'); require_once('database.php'); if(isset($_COOKIE['LoginIdCookie'])) { echo '<h4>Welcome '.$_COOKIE['LoginIdCookie'].'</h4>'; } else{ echo '<h4>Events</h4>';} $result=mysqli_query($dbc,"select * from events") or die('Not Connected'); echo "<html> <body>"; echo "<form method='post' action='EventParticipator.php'>"; echo "<u><h4>Please tick events in which you want to participate</h4></u>"; /*echo "<table cellspacing='0' cellpadding='15'> <th><b>Event Title:</b></th> <th ><b>Event City:</b></th> <th><b>Content:</b></th> <th><b>Images:</b></th> <th><b>Event Date:</b></th>";*/ //while($row=mysqli_fetch_array($result)) $row=mysqli_fetch_array($result); for($i=0;$i<5;$i++) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<tr><td><img src='$Photo' width='120' height='90'/></td><td>$City</td><td>,</td><td>$Date</td><td>:</td><td>$Title</td></tr> <tr><td>$Content</td></tr> <tr><td><a href='#'>Know more</a></td><td>/</td><td><a href='#'>Click here to participate</a></td></tr>"; } //echo "<tr><td><input type='submit' name='submit' value='Participate'</td>"; if(isset($_COOKIE['LoginIdCookie'])) { echo "<td><a href='log_out.php'>Log out</a></td>"; echo "<td><a href='EditActivity.php'>Edit Your Activities</a></td></tr>"; } echo "</table></form></body></html>"; require_once('lower.php'); ?> Quote Hi friends .......... I write above code to display top 5 rows from the database but it not works properly. It displays first row 5 times which is undesireable. Anyone please help????????????????? thanks in advance.................. I have a mysql table that holds data for cars - each car has it's own ID, name, and year. Some cars are repeated. Example: (ID - year - car name) 0001 - 2009 - Honda Civic 0002 - 2008 - Toyota Prius 0003 - 2009 - Honda Civic 0004 - 2008 - Toyota Prius 0005 - 2008 - Toyota Prius 0006 - 2007 - Honda Civic How would I count how many of the same type of cars I have in that table and then display the quantity next to the car name? Like for the above example it would be: 2009 Honda Civic: 2 2007 Honda Civic: 1 2008 Toyota Prius: 3 Thanks in advance for any help :D Morning I have a table with many rows. Some of these rows have the same id number. I'm wondering how I print all the rows with the like id like so programing,design,help. My fucntion is below. function getPostTags($postid){ $sql = mysql_query("SELECT tag FROM tags WHERE id=$postid") or die(mysql_error()); if (mysql_num_rows($e)){ extract(mysql_fetch_array($sql)); $tags[$postid]=array(); $tags[$postid]['tag']; } return $tags; } So if I do this <?php print $tags; ?> It only prints out one result from my table. What do I have to do it get it to print all row field values from the table with a comma. Right now the only way I can do this is instead of printing "$tags" (which only gives me one of the many values) I query the database again and do a while statement with $row = mysql_fetch_array. This isn't the right way to do it. Can someone help or give me some pointers? Thanks for the help. I can't seem to get the math right! I have a function, pulling 13 states (canadian provinces) from the database and I can't seem to get them all to show in 5 columns. Where am I doing this wrong. The code below only shows 7 of 13... I just can't seem to get where I am off! PHP CODE: function map_showCA() { global $db, $tpl; // ShowLocalResources $sSQL = "SELECT * FROM states_canada ORDER BY state;"; $db->query($sSQL); $next_record = $db->next_record(); while ($next_record) { $state_id = $db->f("id"); $state = $db->f("state"); $statename = $db->f("statename"); $statename_html = $db->f("statename_html"); $next_record = $db->next_record(); if (!USE_SEO_LINKS) { $statename_html = $state_id; } $vendors_states[] = array("name" => $statename, "id" => $state_id, "state_html" => $statename_html); } $vendors_states_col = array_chunk($vendors_states, 5, true); $loop = (int)(count($vendors_states) / 5); if(count($vendors_states) % 5 > 0) $loop++; $j = 0; for($i = 0; $i < $loop; $i++) { $parameters = 'http://'.$vendors_states_col[0][$j]["state_html"].'.ilocalize.com'; // $first_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("first_column_link", $parameters); $tpl->set_var("first_column", tohtml($vendors_states_col[0][$j]["name"])); $parameters = 'http://'.$vendors_states_col[1][$j+6]["state_html"].'.ilocalize.com'; // $second_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("second_column_link", $parameters); $tpl->set_var("second_column", tohtml($vendors_states_col[1][$j+6]["name"])); $parameters = 'http://'.$vendors_states_col[2][$j+12]["state_html"].'.ilocalize.com'; // $threeth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("threeth_column_link", $parameters); $tpl->set_var("threeth_column", tohtml($vendors_states_col[2][$j+12]["name"])); $parameters = 'http://'.$vendors_states_col[3][$j+18]["state_html"].'.ilocalize.com'; // $fourth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fourth_column_link", $parameters); $tpl->set_var("fourth_column", tohtml($vendors_states_col[3][$j+18]["name"])); $parameters = 'http://'.$vendors_states_col[4][$j+24]["state_html"].'.ilocalize.com'; // $fifth_column_link = generate_vendor_seo_url($parameters); $tpl->set_var("fifth_column_link", $parameters); $tpl->set_var("fifth_column", tohtml($vendors_states_col[4][$j+24]["name"])); $tpl->parse("ShowLocalResourcesCA", true); $j++; } } HTML CODE: Code: [Select] <table border="0" cellpadding="1" cellspacing="1" class="description_text2" style="padding-bottom:6px;" width="100%" id="dashed_box_gray"> <!--BeginShowLocalResourcesCA--> <tr> <td width="110" align="left" style="padding-left:6px; padding:6px;"><a href="{first_column_link}" class="user_blue_14px">{first_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{second_column_link}" class="user_blue_14px">{second_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{threeth_column_link}" class="user_blue_14px">{threeth_column}</a></td> <td width="109" align="left" style="padding-right:6px; padding:6px;"><a href="{fourth_column_link}" class="user_blue_14px">{fourth_column}</a></td> <td width="108" align="left" style="padding-right:6px; padding:6px;"><a href="{fifth_column_link}" class="user_blue_14px">{fifth_column}</a></td> </tr> <!--EndShowLocalResourcesCA--> </table> i'm trying to echo out the results from a query onto a page, but rather than having them echo out as rows in a table, i want them to be displayed in columns, i.e. first column would have the first 10 results and the second column would have the next to. Any ideas on how i could do this? at the moment i'm using this code to display my results $read=mysql_query("SELECT * FROM entry WHERE category_id=".$id." ORDER BY entry_title") or die("query failed".mysql_error()); $result=mysql_num_rows($read); for($j = 0; $j < $result; $j++) { $row = mysql_fetch_array($read); echo "<a href=article.php?id=".$row['entry_id']. ">".$row['entry_title']."</a><br />"; } but this just displays it as a list down the middle thanks Hi, I have a 'pre-release' sign up form, where people put in their email address and name, and it transmits to a MYSQL database. That's working fine. What I want to do is to have a piece of text that reads: (insert pre release amount of signer upperers here) have signed up. Will you? I'm guessing that the amount of rows on the table, would end up being the number. How do I do this? Thanks, Jack hi friends. to fetch results from the database i made a function and how i call the function on a page like $results = GetResults($someID); when i print_r the $results i get all the results, but now im confused on how do i print the rows individually? say i got Title row how will i only get the Title row from the $results VAR? Folks,
I managed to get this piece of code working. But I need you to check if it is buggy or in error or not. I will add VALIDATION later. Just let me know is this how you query db with mysqli_stmt_bind_result (prepared statement using procedural style) and display results on screen ? Don't worry about pagination. i will add that later. Just let me know if I got the basics correct or not to display results from db or not. That is all. Note my comments in CAPITALS. They are questions to which I need answers. conn.php <?php $db_server = 'localhost'; $db_user = 'root'; $db_password = ''; $db_database = 'test'; $conn = mysqli_connect("$db_server","$db_user","","$db_database"); //SHOULD I KEEP FOLLOWING 1 LINE INTACT HERE OR DUMP IT TO main file search.php ? $conn->set_charset('utf8mb4');//Always use Charset. //HOW TO CONVERT ABOVE LINE TPO PROCEDURAL ? if (!$conn) { //HOW TO WRITE CODE SO FOLLOWING TECHNICAL ERROR IS WRITTEN TO ERROR FILE AND NOT SHOWN TO USER ? //Error Message to show user in technical/development mode to see errors. die("Database Error : " . mysqli_error($conn)); //Error Message to show User in Layman's mode to see errors. die("Database error."); exit(); } ?> Q1. Do not forget to answer my question you see in CAPITALS in above code (conn.php). Check the search.php before replying.
error_reporting.php <?php ini_set('error_reporting','E_ALL'); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); error_reporting(E_ALL); //SHOULD I KEEP FOLLOWING 1 LINE INTACT HERE OR DUMP IT TO main file search.php ? mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); ?> Q2. Do not forget to answer my question you see in CAPITALS in above code (error_reporting.php). Check the search.php before replying.
search.php <?php //include('error_reporting.php'); error_reporting(E_ALL); ini_set('error_reporting',E_ALL); ini_set('display_errors','1'); ini_set('display_startup_errors','1'); ?> <form name = "search" method = "POST" action=""> <label for="keywords">Keywords:*</label> <input type="text" name="keywords" id="keywords" placeholder="Input Keywords" required> <br> <button type="submit">Submit</button><br> <button type="submit" value="submit">Submit</button><br> <input type="submit" value="submit"><br> <button name=submit value=" ">Search</button><br> <button type="submit" name="submit" value="submit">Search</button> <br> <input type="reset"> <br> </form> <?php if($_SERVER['REQUEST_METHOD'] === 'POST') { if(ISSET($_POST['submit'])) { if(ISSET($_POST['keywords'])) { $keywords = $_POST['keywords']; } //SHOULD I KEEP FOLLOWING 1 LINE INTACT HERE OR DUMP IT TO error_reporting.php ? mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); //SHOULD I KEEP FOLLOWING 5 LINES INTACT HERE OR DUMP IT TO conn.php ? $conn = mysqli_connect("localhost","root","","test"); $conn->set_charset("utf8mb4"); if(mysqli_connect_error()) { echo "Could not connect!" . mysqli_connect_error(); } $query = "SELECT page_url,link_anchor_text,page_description,keyphrases,keywords FROM links WHERE keywords = ?"; $stmt = mysqli_stmt_init($conn); //FIRST ATTEMPT TO DISPLAY TBL RESULTS USING mysqli_stmt_bind_result() FUNCTION. TEST RESULT: ATTEMPT A FAILURE! if(mysqli_stmt_prepare($stmt,$query)) { mysqli_stmt_bind_param($stmt,'s',$keywords); $stmt_execution = mysqli_stmt_execute($stmt); if($stmt_execution === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); die; } $bind_result = mysqli_stmt_bind_result($stmt,$page_url,$link_anchor_text,$page_description,$keyphrase,$keywords); if($bind_result === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); die; } $stmt_fetch = mysqli_stmt_fetch($stmt); if($stmt_fetch === FALSE) { printf("Error: %s.\n", mysqli_stmt_error($stmt)); printf("Error: %d.\n", mysqli_stmt_errno($stmt)); die; } while(mysqli_stmt_fetch($stmt)) { echo "$page_url"; echo "<br>"; echo "$link_anchor_text"; echo "<br>"; echo "$page_description"; echo "<br>"; echo "$keyphrase"; echo "<br>"; echo "$keywords"; echo "<br>"; echo "|"; echo "<br>"; } mysqli_stmt_close($stmt); mysqli_close($conn); } else { die("QUERY failed!)"; }
Q3. Anything I should know ? Edited July 17, 2020 by 2020Hey guys so my code below is not working, it will get the app information for the user but its only display 3 results like every time a new user "installs" an new app like it stops showing the last result and starts displaying the new result. Like for example right now it should be showing 7 results but only displaying 3 is there something wrong with my query. (PS: this is just developement testing purposes so thats why my code is sorta sloppy) Thanks!
$default_apps = mysql_query("SELECT * FROM apps WHERE `default`='1'") or die(mysql_error()); $user_apps = mysql_query("SELECT * FROM user_apps WHERE `user_id`='$user_id'") or die(mysql_error()); while($row = mysql_fetch_array($default_apps)) { $url = $row['download_url']; $name = $row['name']; echo $row['name']; echo "<a href='$url'>$name</a><br />"; } while($raw = mysql_fetch_array($user_apps)){ $app_id = $raw['app_id']; } $select_user_apps = mysql_query("SELECT * FROM apps WHERE `app_id`='$app_id' "); while($rop = mysql_fetch_array($select_user_apps)) { $name = $rop['name']; $url = $rop['download_url']; echo $name; echo $url; } Hello all, I have made the multi level marketing downline tree, but the problem with it now, it gives only the downline of one result, as the query gives 2 results what I want now is to make it give the downline of both results not just one, and it's always 2 results, not more here is my code Code: [Select] <?php $id = $_GET['id']; $result = mysql_query("SELECT id FROM users WHERE id = '".$id."' ORDER BY id"); $row = mysql_fetch_assoc($result); if ($row['id'] == 0) { echo" <table> <div id=\".piccenter\""; echo "<tr>"; echo "<img src=\"icon.gif\" border=0 align=\"center\">"; echo ""; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row['id']."'"; echo ""; echo "</div>"; } } $result2 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row['id']."'"); $rows2 = mysql_fetch_assoc($result2); foreach ($rows2 as $row2) { if ($row2['id'] == 0) { echo" <div id=\".picleft\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0 >"; echo "<br />"; echo "'".$row2['id']."'"; echo "</div>"; echo " <td>"; echo "</td> "; } } $result3 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows2['id']."'"); $row3 = mysql_fetch_assoc($result3); if ($row3['id'] == 0) { echo"<div id=\".picright\"> <img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$row3['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result4 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$row3['id']."'"); $rows4 = mysql_fetch_assoc($result4); if ($rows4['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows4['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result5 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows4['id']."'"); $rows5 = mysql_fetch_assoc($result5); if ($rows5['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows5['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result6 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows5['id']."'"); $rows6 = mysql_fetch_assoc($result6); if ($rows6['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows6['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result7 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows6['id']."'"); $rows7 = mysql_fetch_assoc($result7); if ($rows7['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows7['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result8 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows7['id']."'"); $rows8 = mysql_fetch_assoc($result8); if ($rows8['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows8['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> "; } $result9 = mysql_query("SELECT id FROM users WHERE recruiteris = '".$rows8['id']."'"); $rows9 = mysql_fetch_assoc($result9); if ($rows9['id'] == 0) { echo"<img src=\"icon.gif\" border=0 align=\"center\">"; } else { echo "<img src=\"images.png\" border=0>"; echo "<br />"; echo "'".$rows9['id']."'"; echo ""; echo " <tr> <td>"; echo "</td> </tr> </tbody> </table> "; } ?> I'm new to php and been trying to follow along with different tutorials to try and build my own site, i followed a tutorial on making a search feature for the site and have it working perfectly, but i want to change the way how to search displays the results. I want to make it display them how there displayed on the index page. here is the index page how there displayed <div id="table"> <table> <tr class="top"> <th>Account</th> <th>Country</th> <th>Info</th> <th>Login</th> <th>Pass</th> <th>Price</th> <th>Buy</th> </tr> <?php $class = 'grey'; ?> <?php $items = getItems(); ?> <?php if(empty ($items)): ?> <h3>No Items Found</h3> <?php else: ?> <?php foreach($items as $item): ?> <?php $class = ($class == 'grey') ? 'grey2' : 'grey'; ?> <tr class="<?php echo $class; ?>"> <td><?php echo $item['item_account']; ?></td> <td><?php echo $item['item_country']; ?></td> <td><?php echo $item['item_info']; ?></td> <td><?php echo maskUser($item['item_login']); ?></td> <td><?php echo maskPass($item['item_pass']); ?></td> <td><?php echo $item['item_price']; ?> </td> <td><form method="post" action="https://sci.libertyreserve.com/"><input type="submit" name="buy" value="Buy" class="button" /></form></td> </tr> <?php endforeach; ?> <?php endif; ?> how the search is display if (strlen($search) <= 2) { echo 'Search keyword is too short.'; } else { echo "You searched for <b>$search</b><hr size='1'>"; $search_exploded = explode(" ", $search); foreach($search_exploded as $search_each) { $x++; if ($x == 1) $construct .= "item_account LIKE '%$search_each%'"; else $construct .= " OR item_account LIKE '%$search_each%'"; } $construct = "SELECT * FROM items WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum == 0) { echo 'No results found.'; } else { echo "$foundnum results found!</p>"; while ($numrows = mysql_fetch_assoc($run)) { $item_id = $numrows['item_id']; $itemAccount = $numrows['item_account']; $itemI = $numrows['item_info']; $itemLogin = $numrows['item_login']; $itemPass = $numrows['item_pass']; $itemPrice = $numrows['item_price']; echo " <b>$itemAccount</b><br /> $itemI <br /> " . maskUser($itemLogin) . '<br />' . maskPass($itemPass, 0) . '<br />'; } } } my question is im not sure how to edit the search code to display the results in the same format as the index page thanks Hi I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM xbox_games order by gameid"); $row = mysql_fetch_assoc($result); $id = $row["gameid"]; $title = $row["gametitle"]; $cover = $row["cover"]; <?php echo $title;?> Which displays only the first result from my database. How can i change this to display all the results either as a list, or in a table? Thanks |