Jump to content

Problem with loop using php and mysql


mr.web_developer

Recommended Posts

Hi all

 

Good morning / night / afternoon

 

I have a problem I will describe it in detailes

 

I have a database that contain a table called request. It contains 3 names as you can see in the pic

27403895.jpg

 

I would like to print all thoes names in a way we will see it later

let's take a look at the php file

 

[code=php:0]
<?php
$e = mysql_query("select Requster_Name from request");
     while ($row = mysql_fetch_array($e)) {
     extract($row);
     $RN = $row [‘Requster_Name’];
print $easy->display("TEMPLATE.tpl");
         }
?>

[/code]

 

as you can see I'm using template engine

print $easy->display("TEMPLATE.tpl");

 

It will print all the names bu passing it to the template ((template code))

<div id="content" align="center">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse:
collapse;width:333px">
    <tr height="25" style="height:18.75pt">
   <td style="width: 329px; font-size: 14.0pt; font-weight: 700; text-align: center; color: black; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; vertical-align: bottom; white-space: nowrap; border-left: medium none; border-right: 1.5pt solid black; border-top: .5pt solid windowtext; border-bottom: .5pt solid windowtext; padding-left: 1px; padding-right: 1px; padding-top: 1px; background: #C5D9F1">
   {RN}</td>
  </tr>
  </table>
</div>

 

It will print the names like this

16935489.jpg

 

as you can see I'm using the template engine print function inside the while loop

but I want to use it outside the loop for a reason

 

when I take it out the loop

 

<?php
$e = mysql_query("select Requster_Name from request");
     while ($row = mysql_fetch_array($e)) {
     extract($row);
     $RN = $row [‘Requster_Name’];
         }
print $easy->display("TEMPLATE.tpl");
?>

 

It will only print Cris

I hope it's clear

what I want is to print all the names when the print function outside the loop

I want it be print in one record like this

 

95789269.jpg

 

thank you

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/233945-problem-with-loop-using-php-and-mysql/
Share on other sites

Is this smarty templates??

 

Normally you would store the data as an array then assign it

 

PHP:

$e = mysql_query("select Requster_Name from request");
     while ($row = mysql_fetch_assoc($e)) {
     //extract($row);
     $RN[] = $row[‘Requster_Name’];
     }
$easy->assign("RN", $RN);
$easy->display("TEMPLATE.tpl");

 

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.