balkan7 Posted April 24, 2007 Share Posted April 24, 2007 i need help for put in my code other rows from the table, like author, date time and description ... i have no idea how can i put only title show me. here is code: <?php include "connect.php"; include "config.php"; $query = "SELECT * FROM jokes order by id desc"; $result = mysql_query ($query) or die ("Query failed"); $num_cols = 3; $i = 1; echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; while($output = mysql_fetch_array($result)){ if ($i == 1) echo "<tr>"; echo "<td>". $output['joketitle'] ."</td>\n"; if ($i == $num_cols) { echo "</tr>"; $i = 0; } $i++; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/ Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 hope this helps <?php include "connect.php"; include "config.php"; $query = "SELECT * FROM jokes order by id desc"; $result = mysql_query ($query) or die ("Query failed"); echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; //With Titles echo "<tr>"; echo "<td>joketitle</td>\n"; echo "<td>description</td>\n"; echo "<td>author</td>\n"; echo "</tr>"; //end with titles while($output = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>". $output['joketitle'] ."</td>\n"; echo "<td>". $output['description'] ."</td>\n"; echo "<td>". $output['author'] ."</td>\n"; echo "</tr>"; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237205 Share on other sites More sharing options...
jvrothjr Posted April 24, 2007 Share Posted April 24, 2007 $query = "SELECT * FROM jokes order by id desc"; $result = mysql_query ($query) or die ("Query failed"); echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; echo "<tr>"; echo "<td>joketitle</td>\n"; echo "<td>author</td>\n"; echo "<td>date</td>\n"; echo "<td>description</td>\n"; echo "</tr>"; if ($row=mysql_fetch_array($result) ) { do{ echo "<tr>"; echo "<td>". $output['joketitle'] ."</td>\n"; echo "<td>". $output['author'] ."</td>\n"; echo "<td>". $output['F_date'] ."</td>\n"; echo "<td>". $output['Description'] ."</td>\n"; echo "</tr>"; } while($row = mysql_fetch_array($result)); } echo "</table>"; this will create a row for every record found Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237216 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 @jvrothjr, no it won't Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237219 Share on other sites More sharing options...
Trium918 Posted April 24, 2007 Share Posted April 24, 2007 this will create a row for every record found <?php /* All will be selected but only the three columns are displayed*/ $query = "SELECT * FROM jokes order by id desc"; echo "<td>". $output['joketitle'] ."</td>\n"; echo "<td>". $output['description'] ."</td>\n"; echo "<td>". $output['author'] ."</td>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237222 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 yes i know that but i need this ordering whit columns: 1 | 2 | 3 4 | 5 | 6 every column to have rows from table - title, description, date. Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237225 Share on other sites More sharing options...
Trium918 Posted April 24, 2007 Share Posted April 24, 2007 yes i know that but i need this ordering whit columns: 1 | 2 | 3 4 | 5 | 6 every column to have rows from table - title, description, date. What are the fields name? Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237228 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 fields from datebase is : id title description author date Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237234 Share on other sites More sharing options...
Trium918 Posted April 24, 2007 Share Posted April 24, 2007 You only need title, description, date correct? Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237236 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 Surely not this... <?php include "connect.php"; include "config.php"; $query = "SELECT * FROM jokes order by id desc"; $result = mysql_query ($query) or die ("Query failed"); echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; //With Titles echo "<tr>"; echo "<td>joketitle</td>\n"; echo "<td>description</td>\n"; echo "<td>author</td>\n"; echo "</tr>"; //end with titles $num_rows = mysql_num_rows($result); $counter= 0; $output1 = mysql_fetch_array($result); $output2 = mysql_fetch_array($result); $output3 = mysql_fetch_array($result); $output4 = mysql_fetch_array($result); while(($counter*4) =< $num_rows) { $counter++; echo "<tr>"; echo "<td>". $output1['title'] ."</td>\n"; echo "<td>". $output2['title'] ."</td>\n"; echo "<td>". $output3['title'] ."</td>\n"; echo "<td>". $output4['title'] ."</td>\n"; echo "</tr>"; echo "<tr>"; echo "<td>". $output1['description'] ."</td>\n"; echo "<td>". $output2['description'] ."</td>\n"; echo "<td>". $output3['description'] ."</td>\n"; echo "<td>". $output4['description'] ."</td>\n"; echo "</tr>"; echo "<tr>"; echo "<td>". $output1['author'] ."</td>\n"; echo "<td>". $output2['author'] ."</td>\n"; echo "<td>". $output3['author'] ."</td>\n"; echo "<td>". $output4['author'] ."</td>\n"; echo "</tr>"; echo "<tr>"; echo "<td>". $output1['date'] ."</td>\n"; echo "<td>". $output2['date'] ."</td>\n"; echo "<td>". $output3['date'] ."</td>\n"; echo "<td>". $output4['date'] ."</td>\n"; echo "</tr>"; $output1 = mysql_fetch_array($result); $output2 = mysql_fetch_array($result); $output3 = mysql_fetch_array($result); $output4 = mysql_fetch_array($result); } echo "</table>"; ?> **compleatly untested *VERY BAD DESIGN i know! Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237239 Share on other sites More sharing options...
phpbeginner Posted April 24, 2007 Share Posted April 24, 2007 I use a lot of columns in my websites and this works for me ! <?php include "connect.php"; include "config.php"; $rs=mysql_query("select * from jokes ORDER BY id desc"); if($rs) { echo("<table width=100% cellpadding=0 cellspacing=0 align=center>"); while($row=mysql_fetch_row($rs)) { echo("<tr><td width='33%' align='center'>"); echo("<p><b>" . $row[1] . "</b><br>"); echo("</td>"); if($row=mysql_fetch_row($rs)) { echo("<td width='33%' align='center'>"); echo("<p><b>" . $row[2] . "</b><br>"); echo("</td>"); if($row=mysql_fetch_row($rs)) { echo("<td width='33%' align='center'>"); echo("<p><b>" . $row[3] . "</b><br>"); echo("</td>"); echo("</td>"); echo("</tr>"); echo("</table>"); } ; Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237241 Share on other sites More sharing options...
Trium918 Posted April 24, 2007 Share Posted April 24, 2007 Try this: Fix and brake until you get where you are going!!!! <?php include "connect.php"; include "config.php"; $result=mysql_query("select title, description, date from jokes ORDER BY id desc"); print "<table border=1>"; // get field names print "<tr>\n"; while ($field = mysql_fetch_field($result)){ print " <th>$field->name</th>\n"; } // end while print "</tr>\n\n"; // get row data as an associative array while ($row = mysql_fetch_assoc($result)) { print "<tr>\n"; // look at each field foreach ($row as $col=>$val){ print "<td>$val</td>"; } // end foreach print "</tr>\n\n"; } // end while print "<table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237246 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 I use a lot of columns in my websites and this works for me ! <?php include "connect.php"; include "config.php"; $rs=mysql_query("select * from jokes ORDER BY id desc"); if($rs) { echo("<table width=100% cellpadding=0 cellspacing=0 align=center>"); while($row=mysql_fetch_row($rs)) { echo("<tr><td width='33%' align='center'>"); echo("<p><b>" . $row[1] . "</b><br>"); echo("</td>"); if($row=mysql_fetch_row($rs)) { echo("<td width='33%' align='center'>"); echo("<p><b>" . $row[2] . "</b><br>"); echo("</td>"); if($row=mysql_fetch_row($rs)) { echo("<td width='33%' align='center'>"); echo("<p><b>" . $row[3] . "</b><br>"); echo("</td>"); echo("</td>"); echo("</tr>"); echo("</table>"); } ; i have get blank page. Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237274 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 i need this ! Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237276 Share on other sites More sharing options...
phpbeginner Posted April 24, 2007 Share Posted April 24, 2007 Try <?php include "connect.php"; include "config.php"; $rsJokes=mysql_query("select * from jokes ORDER BY id desc"); if($rsJokes) { echo("<table width=100% cellpadding=0 cellspacing=0 align=center>"); while($rowJokes=mysql_fetch_row($rsJokes)) { echo("<tr><td width='33%' align='center'>"); echo("<p>" . $rowJokes[1] . "<br>" . $rowJokes[2]<br>" . $rowJokes[3]""); echo("</td>"); if($rowJokes=mysql_fetch_row($rsJokes)) { echo("<td width='33%' align='center'>"); echo("<p>" . $rowJokes[1] . "<br>" . $rowJokes[2]<br>" . $rowJokes[3]""); echo("</td>"); if($rowJokes=mysql_fetch_row($rsJokes)) { echo("<td width='33%' align='center'>"); echo("<p>" . $rowJokes[1] . "<br>" . $rowJokes[2]<br>" . $rowJokes[3]""); echo("</td>"); echo("</td>"); echo("</tr>"); echo("</table>"); Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237289 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 Parse error: parse error, unexpected '>' in C:\Program Files\xampp\htdocs\jokes\index.php on line 12 Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237298 Share on other sites More sharing options...
balkan7 Posted April 24, 2007 Author Share Posted April 24, 2007 ok i resloved my problem thanks for help ! here is code: <?php include "connect.php"; include "config.php"; $query = "SELECT * FROM jokes order by id desc"; $result = mysql_query ($query) or die ("Query failed"); $num_cols = 3; // columns $i = 1; echo "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n"; while($output = mysql_fetch_array($result)){ if ($i == 1) echo "<tr>"; echo "<td><b>". $output['joketitle'] ."</b><br>".$output['preview']."</td>\n"; if ($i == $num_cols) { echo "</tr>"; $i = 0; } $i++; } echo "</table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237303 Share on other sites More sharing options...
phpbeginner Posted April 24, 2007 Share Posted April 24, 2007 Parse error: parse error, unexpected '>' in C:\Program Files\xampp\htdocs\jokes\index.php on line 12 Sorry bout that mine should have been echo("<p>" . $rowJokes[1] . "<br>" . $rowJokes[2] . "<br>" . $rowJokes[3]""); echo("</td>"); instead of echo("<p>" . $rowJokes[1] . "<br>" . $rowJokes[2]<br>" . $rowJokes[3]""); echo("</td>"); Glad you got it working. Quote Link to comment https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/#findComment-237312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.