Jump to content

[SOLVED] What should I use to echo this ??


yami007

Recommended Posts

well,

This is first I came here, i hope it's my way, so ...

i wanted to echo something like this ...

 

<?php

echo "<table>

<tr>

<td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/><br />{$page["menu_name"]}</a><br /></center></td

           

<td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/><br />{$page["menu_name"]}</a><br /></center></td

           

<td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/><br />{$page["menu_name"]}</a><br /></center></td

           

           

</tr>

      </table>

" ;

?>

 

but i want to show a different content rather to show the same thing three times  ;) PLEASE HELP

Thanks in advance..

Link to comment
https://forums.phpfreaks.com/topic/121720-solved-what-should-i-use-to-echo-this/
Share on other sites

Where is the different content coming from? Where is $page defined?

 

<?php

if (isset($_GET['page'])) {

    $subject_pages = get_pages_for_subject($sel_subject['id']);

    while($page = mysql_fetch_array($subject_pages)) {

   

echo "<table>

  <tr>

  <td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/>

{$page["menu_name"]}[/url]

</center></td

               

  <td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/>

{$page["menu_name"]}[/url]

</center></td

                   

  <td><center><a href=\"index.php?singer=" . urlencode($page["id"]) . "\"><img src=\"{$page["image"]\"/>

{$page["menu_name"]}[/url]

</center></td 

                   

                   

  </tr>

      </table>   

" ;

?>

<?php
if (isset($_GET['page'])) {
$subject_pages = get_pages_for_subject($sel_subject['id']);
echo "<table>";
while($page = mysql_fetch_array($subject_pages)) {
echo " 
<tr>
<td align=\"center\"><a href=\"index.php?singer=" . urlencode($page['id']) . "\"><img src=\"".$page['image']."\"/>".$page['menu_name']."</a>
</td></tr>";
}
echo "</table>";
}
?>

Your already using a while loop then. Maybe your query only returns one row?

 

Also, because your using a loop you don't need to write the code out three times.

 

Also, note the use of


tags on the forum?

 

 

What i tried to say is that i want to display the first three subjects on the first row, and then the second ones....etc..

HOW ??

Right

 

Have a database

Have a row called menu (used here)

Have 3 columns called id, image and name

 

<?PHP
// Connect to database etc

echo "<table>";
$query = mysql_query("SELECT * FROM `menu`");
while ($array = mysql_fetch_array($query)){
echo '
<tr>
<td align="center"><a href="index.php?singer='.$array['id'].'"><img src="'.$array['image'].'" />'.$array['name'].'</a></td>
</tr>';
}
echo "</table>";
?>

right but...

it doesnt come with this...

 

<?php 
echo "<table>";
$query = mysql_query("SELECT * FROM `tbl_pages`");
while ($array = mysql_fetch_array($query)){
echo '
<tr>
<td align="center"><a href="index.php?singer='.$array['id'].'"><img src="'.$array['image'].'" />'.$array['menu_name'].'</a></td>
</tr>';
}
echo "</table>";
?>

sorry guys i should've told you how it was solved, well...

PHPTOM told me to do this ... and it worked  8)

 

<?PHP
// Connect to database etc

echo "<table><tr>";
$rows = 0;
$query = mysql_query("SELECT * FROM `menu`");
while ($array = mysql_fetch_array($query)){


$rows++;
echo '<td align="center"><a href="index.php?singer='.$array['id'].'"><img src="'.$array['image'].'" />'.$array['name'].'</a></td>';
if ($rows %3 == 0) {
echo '</tr><tr>';
}
}
echo "</tr></table>";
?>

 

Thanks PHPTOM..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.