Jump to content

Recommended Posts

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>";

?> 

Link to comment
https://forums.phpfreaks.com/topic/48499-showing-query-in-3-columns/
Share on other sites

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>";

?> 

$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

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";
?>

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!

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>"); 
}
;

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>";
?>

 

 

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.

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>");

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>";

?> 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.