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

 

Link to comment
Share on other sites

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.