PHP - Displaying Database Data In Three Vertical Columns
Hello freaks,
Got a task here which is displaying correctly (I believe). I only have 3 data entries in the db right now. Like I said (I think) the display of the code below yields the right layout but it repeats the first db entry over and over. I got the display to work correctly like this: 1 2 3 4 5 6 7 8 9 I am trying to get this display result (so it is more eligable for the end user!) 1 4 7 2 5 8 3 6 9 Thanks in advance! CODE Code: [Select] <?php include_once "connect_to_mysql.php"; $cols = 3; $result = mysql_query("SELECT plantID, botanicalName FROM plants ORDER BY botanicalName"); $numrows = mysql_num_rows($result); $rows_per_col = ceil($numrows / $cols); $c = 1; $r = 1; while ($row = mysql_fetch_array($result)) { $plantID = $row["plantID"]; $botanicalName = $row["botanicalName"]; if ($r == $rows_per_col) { $c++; $r = 1; } else { $r++; } } $dyn_table = '<table width="750" cellpadding="0" cellspacing="0" border="0">'; for ($r = 1; $r <= $rows_per_col; $r++) { $dyn_table .= '<tr>'; for ($c = 1; $c <= $cols; $c++) { $dyn_table .= '<td><a href="plant_details.php?plantID = ' . $plantID . '" id="plantLink">' . $botanicalName . '</a></td>'; } $dyn_table .= '</tr>'; } $dyn_table .= '</table>'; ?> Similar TutorialsHi, This has been baffling me for a couple hours now and i cant seem to figure it out. I have some code which creates an array and gets info from a mysql database and then displays in a list. This works great but after adding more and more rows to my database the list is now becoming quite large and doesnt look great on my site. Is it possible to split the list into multiple columns of about 25 and if possible once 3 or 4 columns have been created start another column underneath. To help explain i would be looking at a layout as follows: Code: [Select] line 1 line 1 line 1 line 2 line 2 line 2 ... ... ... line 25 line 25 line 25 line 1 line 1 line 1 line 2 line 2 line 2 ... ... ... line 25 line 25 line 25Im guessing there should be some sort of if statement to check how many items are being displayed and to create a new column if necessary. Is this correct? Thanks, Alex Hi, I'm trying to joing two tables together, in the resulting PHP coding (See below) the issue I'm having the coding saying select the colour from the colour table where the model of car is the same as the model in the cars table. For example, if the car model is KA and in the table it is KA show the colours. I know this manual fix does the trick. [ $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = '$test' "; ] But not the soultion any help would be much appericated thank you. [ include "connections/dbconnect.php"; $manfactures = "Ford"; $car_query = "SELECT * FROM cars WHERE make = '$manfactures'"; $car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error()); setlocale(LC_MONETARY, 'en_GB'); $fmt = '%i'; if (mysql_num_rows($car_result) > 0) { while ($car_row = @ mysql_fetch_array($car_result)) { $test = "KA"; $query_cols = "SELECT * FROM colours WHERE colours.model = cars.model"; $cols_result = mysql_query($query_cols) or die ("Error in query: $query_cols. ".mysql_error()); print " <table class='details'> <tr> <td rowspan='2'> <img src=\"". $car_row["image"] ."\" alt='" . $car_row["image_alt"] . "' /> </td> <td colspan='2'> <a href='" . $car_row["what_link"] . "'> " . $car_row["model"]." ".$car_row["model_details"] . " </a> </tr> <tr> <td> <p class='info'> RRP:<br/> What Price:<br/> Our Price:<br/> Savings of:<br/> Delivery Time: </p> </td> <td> <p class='info1'> "; echo money_format($fmt, $car_row["rrp"] ); print "<br/>"; echo money_format($fmt, $car_row["what_price"] ); print "<br/>"; echo money_format($fmt, $car_row["our_price"] ); $savings = $car_row["rrp"] - $car_row["our_price"]; print " <br/> <font color=\"red\">"; echo money_format($fmt, $savings ); print " </font><br/> " . $car_row["delivery_time"] . " </p> </td> </tr> <tr> <td> "; while ($cols_row = @ mysql_fetch_array($cols_result)) { ?> <a href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $cols_row["colour"] . ""; ?>");return false'> <?php print " <img src=\"". $cols_row["colour_img"] ."\" alt='" . $cols_row["colour_img_alt"] . "' /> "; } print " </td> </tr> "; } } else { echo "Aids!"; } print "</table>"; ?>] So I have an simple account centre up, and i'm wanting to display their 'Name' 'Username' and 'Email' as part of their details. But I have one problem... My code doesn't seem to be getting the data from my database... It may be messy to some people, just warning you! Code: [Select] <?php session_start(); if($_SESSION['username']){ $connect = mysql_connect("****","****","****") or die("Could not connect to database."); mysql_select_db("****") or die ("Could not find database!"); $sql = mysql_query("SELECT * FROM login"); $username = $rows['username']; $email = $rows['email']; $rows = mysql_fetch_assoc($sql); echo "<p>"; } else header("location: suggestion.html"); ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> body { background-color: #CCC; } body,td,th { color: #000; font-family: "MS Serif", "New York", serif; } </style> </head> <body> <div id="wrap"> <!--Header--> <div id="header_member"> </div> <!--Log out and time--> <div id="info"> <div id="date"><script type="text/javascript"> var currentDate = new Date() var day = currentDate.getDate() var month = currentDate.getMonth() + 1 var year = currentDate.getFullYear() document.write("<b>" + day + "/" + month + "/" + year + "</b>") var currentTime = new Date() var hours = currentTime.getHours() var minutes = currentTime.getMinutes()</script> </div> <div id="time"><script type="text/javascript"> var suffix = "AM"; if (hours >= 12) { suffix = "PM"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) minutes = "0" + minutes document.write("<b>" + hours + ":" + minutes + " " + suffix + "</b>")</script> </div> </div> <div id="logout"><center><?php echo "<a href='logout.php'>Log out.</a>";?></center></div> <!--Main section which will contain everything else--> <div id="member_main"> <div id="member_right"><center> <p><img src="images/accountinf.png" width="175" height="30" /></p> <p>Name: <?php echo $username;?></p> <p>Email: <?php echo $email;?></p> </center> </div> <div id="member_top"><center><?php echo "Welcome, ".$_SESSION['username'];?></center></div> <div id="member_left" align="center"><img src="images/navigation.png" width="105" height="30" /><img src="images/home_member.png" width="105" height="30" /><img src="images/account.png" width="105" height="30" /></div> </div> <!--Footer--> <div id="footer_member"></div> </div> </body> </html> PHP Code Code: [Select] <?php $username=""; $password=""; $database=""; mysql_connect("","",""); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM tablename"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"id"); $field2-name=mysql_result($result,$i,"Location"); $field3-name=mysql_result($result,$i,"Property type"); $field4-name=mysql_result($result,$i,"Number of bedrooms"); $field5-name=mysql_result($result,$i,"Purchase type"); $field6-name=mysql_result($result,$i,"Price range"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> HTML code for the form Code: [Select] <table id="tb1"> <tr> <td><p class="LOC">Location:</p></td> <td><div id="LC"> <form action="insert.php" method="post"> <select multiple="multiple" size="5" style="width: 150px;" > <option>Armley</option> <option>Chapel Allerton</option> <option>Harehills</option> <option>Headingley</option> <option>Hyde Park</option> <option>Moortown</option> <option>Roundhay</option> </select> </form> </div> </td> <td><p class="PT">Property type:</p></td> <td><div id="PS"> <form action="insert.php" method="post"> <select name="property type" style="width: 170px;"> <option value="none" selected="selected">Any</option> <option value="Houses">Houses</option> <option value="Flats / Apartments">Flats / Apartments</option> </select> </form> </div> </td><td> <div id="ptype"> <form action="insert.php" method="post"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </form> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <form action="insert.php" method="post"> <select name="number of bedrooms"> <option value="none" selected="selected">No Min</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> to <select name="number of bedrooms"> <option value="none" selected="selected">No Max</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> </form> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <form action="insert.php" method="post"> <select name="price range"> <option value="none" selected="selected">No Min</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> to <select name="price range"> <option value="none" selected="selected">No Max</option> <option value="50,000">50,000</option> <option value="60,000">60,000</option> <option value="70,000">70,000</option> <option value="80,000">80,000</option> <option value="90,000">90,000</option> <option value="100,000">100,000</option> <option value="110,000">110,000</option> <option value="120,000">120,000</option> <option value="130,000">130,000</option> <option value="140,000">140,000</option> <option value="150,000">150,000</option> <option value="160,000">160,000</option> <option value="170,000">170,000</option> <option value="180,000">180,000</option> <option value="190,000">190,000</option> <option value="200,000">200,000</option> <option value="210,000">210,000</option> <option value="220,000">220,000</option> <option value="230,000">230,000</option> <option value="240,000">240,000</option> <option value="250,000">250,000</option> <option value="260,000">260,000</option> <option value="270,000">270,000</option> <option value="280,000">280,000</option> <option value="290,000">290,000</option> <option value="300,000">300,000</option> <option value="310,000">310,000</option> <option value="320,000">320,000</option> <option value="330,000">330,000</option> <option value="340,000">340,000</option> <option value="350,000">350,000</option> </select> </form> </div> </td> </tr> </table> </div> <form id="submit" action=""> <input type="submit" value="search" /> </form> I am trying to display data from a database from a form entry here is the php <?php include('dbconnect.php'); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM child_info"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); echo "<b><center>Database Output</center></b><br><br>"; $i=0; while ($i < $num) { $field1-name=mysql_result($result,$i,"file_number"); $field2-name=mysql_result($result,$i,"first_name"); $field3-name=mysql_result($result,$i,"middle_name"); $field4-name=mysql_result($result,$i,"last_name"); $field5-name=mysql_result($result,$i,"birthdate"); $field6-name=mysql_result($result,$i,"gender"); $field7-name=mysql_result($result,$i,"features"); $field8-name=mysql_result($result,$i,"diagnosis"); $field9-name=mysql_result($result,$i,"description"); echo "<b>$field1-name $field2-name2</b><br>$field3-name<br>$field4-name<br>$field5-name<hr><br>"; $i++; } ?> here is the form I am using <form name="child_info" action="selectdata.php" method="post" id="child_info"> <table width="444" align="center" > <tr> <td> Search by Name: </td> <td> First Name:<input type="text" class="form-textbox " id="first_name" name="first_name" size="20" /><br /> Last Name:<input type="text" class="form-textbox " id="last_name" name="last_name" size="20" /> </td> </tr> <tr> <td width="208"> Choose Male or Female: </td> <td width="224"> <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="Female" /> Female </td> </tr> <tr> <td> Choose age range: </td> <td> <select name="first_age" id="first_age"> <option value="00">From</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> <select name="second_age" id="second_age"> <option value="00">To</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> </select> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> <input type="reset" name="reset" id="reset" value="reset" /> </div></td> </tr> </table> </form> first problem is getting the form to use the php second problem is when i try to use the php alone is I get this error Parse error: syntax error, unexpected '=' in /home/fathersh/public_html/selectdata.php on line 17 17 is highlighted above in the php Hey, I have written a script for a very simple PHP wall and comment system. This works fine but the problem I have is displaying the comments. It seems to display the comments associated with the post as well as the comments on the posts above it. I have checked the database and the post ID's are correct. Here is my code: Code: [Select] <?php $wallDisplay = ''; $commentDisplay = ''; $wallDisplaySql = mysql_query("SELECT * FROM wall WHERE to_id='$id' ORDER BY datetime DESC") or die (mysql_error()); while($row = mysql_fetch_array($wallDisplaySql)){ $wallPostId = $row["id"]; $to_id = $row["to_id"]; $from_id = $row["from_id"]; $message = $row["message"]; $dateTime = $row["datetime"]; $getFromData = mysql_query("SELECT username FROM members WHERE id='$from_id'") or die (mysql_error()); while($row2 = mysql_fetch_array($getFromData)){ $wallUsername = $row2['username']; } $displayComments = mysql_query("SELECT * FROM wallComments WHERE wallPostId='$wallPostId' ORDER BY datetime DESC"); while($row3 = mysql_fetch_array($displayComments)){ $wallComment = $row3['comment']; $commentFrom = $row3['from_id']; $commentDate = $row3['datetime']; $getUsername = mysql_query("SELECT username FROM members WHERE id='$commentFrom'"); while($row4 = mysql_fetch_array($getUsername)){ $commentUsername = $row4['username']; } $cheersCheck_pic = "members/$commentFrom/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $commentDisplay .= '<table width="500px" align="right" cellpadding="4" bgcolor="#FFF"> <tr> <td width="10%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $commentFrom . '">' . $cheers_pic . '</a><br /> </td> <td width="90%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $commentFrom . '"><span class="blackText">' . $commentUsername . '</span></a> • <span class="blackTetx">' . $commentDate . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $wallComment . '</span></td> </tr> </table>'; } $cheersCheck_pic = "members/$from_id/pic1.jpg"; $cheersDefault_pic = "members/0/defaultMemberPic.jpg"; if (file_exists($cheersCheck_pic)) { $cheers_pic = "<img src=\"$cheersCheck_pic?$cacheBuster\" width=\"40px\" />"; } else { $cheers_pic = "<img src=\"$cheersDefault_pic\" width=\"40px\" />"; } $wallDisplay .= '<table width="100%" align="center" cellpadding="4" bgcolor="#FFF"> <tr> <td width="7%" bgcolor="#FFFFFF"><a href="member_profile.php?id=' . $from_id . '">' . $cheers_pic . '</a><br /> </td> <td width="93%" bgcolor="#DBE4FD"><a href="member_profile.php?id=' . $from_id . '"><span class="blackText">' . $wallUsername . '</span></a> • <span class="blackTetx">' . $dateTime . '<br /><font size="1"></font></span><br /> <span class="blackText">' . $message . '</span></td> </tr> </table> <div id="commentList">' . $commentDisplay . '</div> <div id="comment" align="right"> <form id="comment" name="comment" method="post" action="member_profile.php?id=' .$id. '"> <textarea name="comment" id="comment" rows="1" cols="35"></textarea> <input type="hidden" name="wallPostId" id="wallPostId" value="'. $wallPostId .'" /> <input type="hidden" name="commentFrom" id="commentFrom" value="'. $_SESSION['id'] .'" /> <input type="submit" name="submitComment" id="submitComment" /> </form> </div><br /> '; } ?> I have been looking at it for ages but can think why this is happening. Thanks in advance for any help ok so im sure this is only a small problem but still here it is: im making a shopping list app where users can create a list...when they view the list they can populate it with categories such as frozen food, fruit, veg etc etc...they can then populate categories with items such as apples, potatoes or ice cream etc etc. now i have some data in the database already...and i wanted to display it on the page like this. ASDA SHOPPING LIST fruit apples bananas plums veg potatoes carrots frozen burgers chips ice cream however at the moment with my code it displays like this: ASDA SHOPPING LIST fruit apples bananas plums potatoes carrots burgers chips ice cream veg frozen here is my code: include_once("config_class.php"); $db = new db(); // open up the database object $db->connect(); // connect to the database //getting id of the data from url $id = $_GET['id']; $sql=mysql_query("SELECT listname FROM list WHERE listid=$id") or die("cannot select: ".mysql_error()); $sql2=mysql_query("SELECT catid, category FROM cat WHERE listid=$id") or die("cannot select: ".mysql_error()); $sql3=mysql_query("SELECT items.itemname, items.itemid, cat.catid FROM items, cat WHERE cat.catid=items.catid") or die("cannot select: ".mysql_error()); $temp_cat = ""; $res=mysql_fetch_array($sql); echo "<b>" . $res['listname'] . "</b>" . "<br><br>"; echo "<form action='addcat.php?id=$id' method='post'>"; echo "<input type='text' id='addcat' name='addcat'>"; echo "<input type='submit' value='Add Category'>"; echo "</form>"; while($res2=mysql_fetch_array($sql2)) { echo "<table cellpadding='2' cellspacing='2' width='800'>"; echo "<tr>"; if($res2['category'] != $temp_cat ) { echo "<td width='20%'>"; echo "<b>" . $res2['category'] . "</b>" . "</td>"; echo "<td width='20%'><a href='delcat.php?id=$res2[catid]&id2=$id'>Delete Category</a></td>"; echo "<form action='additem.php?id=$res2[catid]&id2=$id' method='post' name='form1'>"; echo "<td width='20%'>"; echo "<input type='text' name='itemname'></td>"; echo "<td width='20%'>"; echo "<input type='submit' name='Submit' value='Add Item'></td>"; echo "</form>"; echo "</tr>"; $temp_cat=$res2['category']; } while($res3=mysql_fetch_array($sql3)) { echo "<tr>"; echo "<td width='20%'>"; echo "$res3[itemname]" . "</td>"; echo "<td width='20%'>"; echo "<a href='delitem.php'>Delete Item</a>" . "</td>"; echo "</tr>"; } echo "</table>"; } could someone please help me display this correctly? thanks in advance Hey guys, I wrote a code for displaying images in columns, but for some reason it's not working. Can you take a look and tell me what I'm doing wrong? $i = 0; if($i % 4 == 0){ echo ' <td width="25%" align="center" valign="top"> <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'"width="200" height="150" border="0"></a><br> </td> <td width="25%" align="center" valign="top"> '.$naziv.' - '.$mjesto.' </td> <td width="25%" align="center" valign="top"> '.$medalja.' </td><br /> '; echo '</tr><tr>'; } $i++; } The output I'm getting now is one image below another. I would like to display them one next to another. Please help!!! Code: [Select] <?php $result = mysql_query("SELECT * FROM FamilyTbl INNER JOIN PeopleTbl ON (FamilyTbl.Name_ID = PeopleTbl.NameID) WHERE FamilyTbl.House_ID = '$address' ORDER BY NameLast, NameFirst ") OR die(mysql_error()); WHILE ($row = mysql_fetch_array($result) ) { echo $row[NameLast]. ", ". $row[NamePrefix]. " ". $row[NameFirst]. " ". $row[NameMiddle]. $row[NameSuffix]. " "; } ?> OK, some of these queries return A LOT of names. I'd like to be able to display them in columns in a table like so: Code: [Select] Charne, Mr. Michael Glanger, Mrs. Karin Kling, Mr. Wayne Charne, Mrs. Suzette Glanger, Mr. Trevor Lazarow, Mrs. Fiona Charney, Mrs. Linda Jochelson, Mrs. Barbara Lazarow, Mr. Mark Charney, Mr. Norman Jochelson, Mr. Neil Norton, Mr. Charles Cohen, Mr. Brendan Karlan, Mr. Dennis Norton, Mrs. Jodi Cohen, Mrs. Joanna Karlan, Mrs. Helen Roy, Mr. Michael Flekser, Mrs. Jean Kling, Mrs. Danielle Roy, Mrs. Nicki Frysh, Dr. Howard Kling, Mrs. Melanie Tsafrir, Mrs. Lauren Frysh, Mrs. Sandra Kling, Mr. Nevil Tsafrir, Mr. Thomer That way it reads top to bottom THEN left to right. math-wise, it's simple to set up: Code: [Select] $num_results = number_of_$results; $numcols = 3; $numrows = trunc($numresults/numcols); <table> for row_loop=1 to numrows <tr> for col_loop = 1 to numcols <td> echo result(col_loop-1)*(numrows)+row_loop </td> next col_loop </tr> next row_loop </table> Anyone want to give this a shot? Revraz already directed me to http://www.phpfreaks.com/forums/index.php/topic,95426.0.html but that displayed the data from left to right then up to down like so: Code: [Select] Charne, Mr. Michael Charne, Mrs. Suzette Charney, Mrs. Linda Charney, Mr. Norman Cohen, Mr. Brendan Cohen, Mrs. Joanna Flekser, Mrs. Jean Frysh, Dr. Howard Frysh, Mrs. Sandra Glanger, Mrs. Karin Glanger, Mr. Trevor Jochelson, Mrs. Barbara Jochelson, Mr. Neil Karlan, Mr. Dennis Karlan, Mrs. Helen Kling, Mrs. Danielle Kling, Mrs. Melanie Kling, Mr. Nevil Kling, Mr. Wayne Lazarow, Mrs. Fiona Lazarow, Mr. Mark Norton, Mr. Charles Norton, Mrs. Jodi Roy, Mr. Michael Roy, Mrs. Nicki Tsafrir, Mrs. Lauren Tsafrir, Mr. Thomer It's a good temp solution, but if anyone is good with for loops, I'd appreciate the help, thanks! -Dave Hi, I am stuck. I have used dreamweaver to create a master details page with links to the details page successfully, but I would like to display the master details page results in 3 columns rather than the 1 column that dreamweaver defaults. As the site becomes richer the content will increase yielding many results, therfore the content displayed in a single column will require the users to scroll way down the page. So, as it is now the results display as follows: Plant1 Plant2 Plant3 Plant4 Plant5 Plant6 Plant7 Plant8 Plant9 etc... I would like them to display as follows: Plant1 Plant4 Plant7 Plant2 Plant5 Plant8 Plant3 Plant6 Plant9 Here is my code thus far: <?php require_once('Connections/connGND.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_connGND, $connGND); $query_rsBotanicalA = "SELECT * FROM plants WHERE CatIDB = 'A'"; $rsBotanicalA = mysql_query($query_rsBotanicalA, $connGND) or die(mysql_error()); $row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA); $totalRows_rsBotanicalA = mysql_num_rows($rsBotanicalA); ?> <table border="0" align="left"> <?php do { ?> <tr> <td align="left"><a href="plantdetails.php?recordID=<?php echo $row_rsBotanicalA['PlantID']; ?>"> <?php echo $row_rsBotanicalA['BotanicalName']; ?> </a></td> </tr> <?php } while ($row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA)); ?> </table> Could someone help me to write this code, as I have been unsuccessful maintaining the links. I have been able get the results to display in the columsn as I would like, but I haven't been able to figure it out while maintaining the links! Thanks. Hi, I would like to display my master details page links to the details pages in three columns rather than a single column. Below is the do-while code I have thus far, and I am stuck. Could someone please mock up this code quick, because I know it is a simple syntax error somewhere. <?php do { echo "<table border='0'>"; for ($y=1; ; $y++) { echo "<tr>"; for ($x=1; $x<=3; $x++) { echo "<td align='left'><a href="plantdetails.php?recordID=echo $row_rsBotanicalA['PlantID'];">; echo $row_rsBotanicalA['BotanicalName']; </a></td>" } echo "</tr>"; } } while ($row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA)); echo "</table>"; ?> I have a search set up to search a table for the text entered in a textbox, I have two columns in the table, one with the first name of people, and the second with their last names, I am wondering how I can search both, so for instance: I type in the search field: Roger Smith in the database it would look like: First_name-----|-----Last_name -------------------|------------------- Roger------------|-------Smith my current query is: Code: [Select] $query = mysql_query("SELECT * FROM users WHERE fname LIKE '%$find%' OR lname LIKE '%$find%'"); But if I type both parts of the name it doesn't return anything. works fine if I just search for "Roger" OR "Smith". What I want to do is what is in the shown in the table. I want to only get the Math subject and order the units from unit 1 (UI) to the last available unit in the database; after this, under each unit, to show the homework related to each unit. I have tried to save it into an array with mysql_fetch_array but it stores the row that involves one unit. I want all the units and only the units with their homework under them.
My database is attached to this post in a txt file.
hope someone can help.
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin tÃtulo</title> </head> <body> <form action="" method="post" name="form1" id="form1"> <table width="200" border="1"> <tr> <td>Subject:</td> <td>Math</td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>UI</td> <td>UI</td> <td>UII</td> <td>UIII</td> <td>UII</td> <td>...</td> </tr> <tr> <td>Home work</td> <td>Math work1</td> <td>Math work2</td> <td>Math work3</td> <td>Math work4</td> <td>Math work5</td> <td>...</td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> </body> </html> I'm trying to create a sitemap page. With Main categories and then sub categories. Some have no subcategories and some have a lot. I want them evenly distributed into each column. I can't seem to find a script. Can someone help? I want it to look similar to this http://www.walmart.com/cp/All-Departments/121828 Here is a small portion of the categories: Code: [Select] <ul class="dirlist"> <li><a class="s1" href="Accessories.htm"><b>A</b>ccessories</a></li> <ul class="subcats"> <li><a href="Belts.htm">Belts</a></li> <li><a href="Gloves-and-Mittens.htm">Gloves & Mittens</a></li> </ul> <li><a class="s1" href="Activewear.htm"><b>A</b>ctivewear</a></li> <li><a class="s1" href="Handbags-and-Luggage.htm"><b>H</b>andbags & Luggage</a></li> <ul class="subcats"> <li><a href="Backpacks.htm">Backpacks</a></li> <li><a href="Briefcases.htm">Briefcases</a></li> <li><a href="Computer-Bags.htm">Computer Bags</a></li> </ul> </ul> Hi, I have this script that returns the entire table including column names and the row data. However I only want certain column names and the corresponding data to be returned. Code: [Select] <?php include_once("data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $db = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die ("Error connecting to database"); mysql_select_db("$dbname", $db) or die ("An error occured when connecting to database"); // sending query $result = mysql_query("SELECT * FROM members"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: members</h1>"; echo "<table border='1'><tr>"; for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_query($result); ?> Any help is always appreciated I have a blog on my website and the blogs content is stored in a database. On my home page I have the two recent articles displayed on my home page but I have to change them manually so I add the recent article on the home page in the first column and the second most recent one in the next column so they are side by side. What I want to do is automatically display the blogs image and blog title from the database and display on the home page so I don't have to keep changing it manually My current code looks like the following <div class="block"> <div class="container"> <h3 class="text-center"><span class="color">Recent Blog Articles</span></h3> <div class="row"> <div class="col-md-6"> <div class="text-img animation" data-animation="fadeInLeft" data-animation-delay="0.5s"> <a href="https://www.it-doneright.co.uk/blog/one-year-to-go-until-end-of-support-for-windows-7"> <div class="image"> <img class="img-responsive" src="https://www.it-doneright.co.uk/images/blog/windows7-eos-new.jpg" alt="One year to go until end of support for Windows 7"> </div> <p>One year to go until end of support for Windows 7</p> </a> </div> </div> <div class="col-md-6"> <div class="text-img animation" data-animation="fadeInLeft" data-animation-delay="0.5s"> <a href="https://www.it-doneright.co.uk/blog/windows-10-is-going-to-require-7gb-of-storage-for-future-updates"> <div class="image"> <img class="img-responsive" src="https://www.it-doneright.co.uk/images/windows-ten-updates-needing-7gb-space-on-hard-drive.jpg" alt="Windows 10 is going to require 7gb of storage for future updates"> </div> <p>Windows 10 is going to require 7gb of storage for future updates</p> </a> </div> </div> </div> </div> </div> I did look on Google before posting but could not get my head around how to do it, could anyone point me in the right direction or start me off and will have a go 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 Hello, I have a script that processes data from a form, and then outputs data from a MySQL table based on which selections are made on the form. What I'm trying to do is create columns showing data for each month depending on which months the user selects, and then a "Total" column at the end of that. The output first determines the "family" the results are in, then the ID the product is for the parent family, and then it outputs the data based on what ID is listed. Unfortunately, I have no idea how to do this without nesting while loops inside other while loops which I know is bad for server performance - and yes this does take a long time to complete. Here is some of my code for this to show what I'm doing wrong: Code: [Select] $searchdatabase5 = "SELECT field3 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field3 != 0 AND field4 != '995' GROUP BY field3"; $run5 = mysql_query($searchdatabase5) or die(mysql_error()); while($row5 = mysql_fetch_assoc($run5)) { $field5_3 = $row5['field3']; echo '<tr><td colspan="0"><hr style="width: 100%; height: 1px; color: #a0a0a0;"></td></tr><tr><td colspan="0" bgcolor="#ccffcc"><strong>FAMILY '. $field5_3 .'</strong><br /></td></tr>'; $searchdatabase12 = "SELECT field4 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field3 = '$field5_3' AND field4 != 0 GROUP BY field4"; $run12 = mysql_query($searchdatabase12) or die(mysql_error()); while($row12 = mysql_fetch_assoc($run12)) { $field12_4 = $row12['field4']; $searchdatabase6 = "SELECT field3,field4,field5,field6 FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field4 = '$field12_4' GROUP BY field3,field4,field5"; $run6 = mysql_query($searchdatabase6) or die(mysql_error()); while($row6 = mysql_fetch_assoc($run6)) { $field6_3 = $row6['field3']; $field6_4 = $row6['field4']; $field6_5 = $row6['field5']; $field6_6 = $row6['field6']; echo '<tr><td colspan="0">'. $field6_5 .' - '. $field6_6 .'</td></tr><tr><td valign="middle" align="left" bgcolor="#ccc" width="183px">Units</td>'; $searchdatabase7 = "SELECT * FROM slssum2 WHERE company = '$companyname' AND CONCAT(year,month) BETWEEN '$startyear$startmonth' AND '$endyear$endmonth' AND field5 = '$field6_5' ORDER BY year,month ASC"; $run7 = mysql_query($searchdatabase7) or die(mysql_error()); while($row7 = mysql_fetch_assoc($run7)) { $field7_3 = $row7['field3']; $field7_4 = $row7['field4']; $field7_5 = $row7['field5']; $field7_9 = $row7['field9']; $field7_10 = $row7['field10']; $field7_month = $row7['month']; $field7_year = $row7['year']; $startmonth2 = ltrim($startmonth, '0'); echo '<td bgcolor="#e6e6e6" width="95px" nowrap="nowrap" align="right">'; echo $field7_10; echo '</td>'; } Here is the output: I know the code is very bad, but what would be the best way to recreate what I have in the image? Thank you. right now it displays the first column of the array as a header for each foreach loop then i've got the data displayed under each header and it has 4 columns or a number of my choosing with data displayed under the Table Headings. I am trying to make it display 4 or so columns but with the each group having a certain number of grouped table (data/header) in each column. a different amount for each column that i can choose IF Possible i'd like the choice of being able to remove the headers eg. Z when there is no data in them. This is an example of how it is being displayed right now Any Help would be greatly appreciated Quote A Airlie Beach Andergrove Alexandra Armstrong Beach Alligator Creek B Bucasia Blacks Beach Beaconsfield Bakers Creek Balberra Bloomsbury Breadalbane Ball Bay Belmunda C Cannonvale Calen Crystal Brook Cremorne Chelona Campwin Beach Cape Hillsborough Conway Heres The Code i have so far. Code: [Select] <?php $file = "widget.csv"; @$fp = fopen($file, "r") or die("Could not open file for reading"); $outputArray = array(); $count = 0; while(($shop = fgetcsv($fp, 1000, ",")) !== FALSE) { $outputArray[array_shift($shop)] = array_filter($shop); } echo "<table>"; foreach ($outputArray as $alphabetical=>$value){ echo "<th colspan='4'><b>" . $alphabetical ."</b></th>"; echo "<tr>"; foreach ($value as $key){ $afterkey=preg_replace('/\s+/','-',$key); if ($count == 4){ echo '</tr><tr><td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; $count = 0; }else{ echo '<td><a href="map.php?mapaddress='.$afterkey.'-qld&mapname='.$key.'">'.$key.'</a></td>'; } $count++; } echo "</tr>"; $count = 0; } echo "</table>"; echo "\n<br />"; ?> Heres an example of what i am trying to do. A D K N S AlexandraHeadlands DickyBeach KingsBeach Nambour SandstonePoint Aroona Diddillibah KielMountain Ninderry ShellyBeach Doonan KundaPark NoosaHeads SippyDowns B Dulong Kuluin Ningi SunriseBeach Beachmere DeceptionBay Kilcoy NorthArm SunshineBeach BanksiaBeach Noosaville Scarborough Beerburrum E L Beerwah EerwahVale Landsborough O T Bellara Elimbah Tanawha Bellmere Eudlo M P TowenMountain Birtinya Eumundi Maleny Petrie Tewantin Bongaree Mapleton Palmview TwinWaters Bokarina F Marcoola Palmwoods BribieIslandArea Flaxton MarcusBeach Parklands U Buddina ForestGlen MaroochyRiver Parrearra UpperCaboolture Burnside Maroochydore PeregianBeach Buderim G Minyama Pinbarren V Burpengary GlassHouseMountains MoffatBeach PointArkwright Valdora BliBli Mons PelicanWaters H Montville PacificParadise W C Highworth Mooloolaba WeybaDowns CoolumBeach Hunchy Mooloolah Q Warana Caboolture MountainCreek WestWoombye CabooltureSouth I MountCoolum R Woombye Caloundra ImageFlat Morayfield Rosemount Woorim CastawaysBeach Mudjimba Redcliffe WamuranBasin Chevallum J Woodford CoesCreek WoodyPoint Cooroy Wamuran Currimundi Wurtulla X Y YandinaCreek Yandina Z |