- $result = mysql_query("SELECT * FROM product inner join members ON product_member_id = members_sid WHERE members_username='username'") ;
-
-
while($row = mysql_fetch_array($result))
-
{
-
$template->assign_vars(array(
-
'PRODUCT' => $row['product_title'],
-
'USERNAME' => $row['members_username'],
-
'COUNTRY' => $row['members_country'],
-
-
));
when I use this code, I try to display all the products linked to the 'username', it only displays ONE product.
I am trying to get it to display all of the products.I used the while loop ...it still displays just one.
any suggestions? Thank you
5 2611 Atli 5,058
Expert 4TB
Hey.
Knowing nothing about the template class you are using, I would guess that you keep overwriting the same variables each loop, therefore only displaying the last row returned by your query.
If you need to pass multiple values for the same variable, you need to use an array.
any example?
to assign a variable to the template you use :
$template->assign_vars(array(
'PRODUCT' => $row['product_title']
'variable' => $variable
etc etc))
Atli 5,058
Expert 4TB
What you are assigning the template right now is a list of variables that looks something like this: - $var = array(
-
'PRODUCT' => 'p1',
-
'USERNAME' => 'u1',
-
'COUNTRY' => 'c1'
-
);
I'm assuming here that each of the element names there ("PRODUCT", "USERNAME" and "COUNTRY") represents a variable name available to your template.
In that case, to assign a list of values for each of them you would want their values to be an array. Somewhat more like this: - $var = array(
-
'PRODUCT' => array('p1', 'p2', 'p3'),
-
'USERNAME' => array('u1', 'u2', 'u3'),
-
'COUNTRY' => array('c1', 'c2', 'c3')
-
);
However, a better approach might be to assign a single two-dimensional array, containing a list of product. That makes it easier to loop through in your template. (Assuming, of course, that your template system is capable of that.) - $var = array(
-
'products' => array(
-
array(
-
'title' => 'product 1',
-
'username' => 'user 1',
-
'country' => 'country 1'
-
),
-
array(
-
'title' => 'product 2',
-
'username' => 'user 2',
-
'country' => 'country 2'
-
),
-
array(
-
'title' => 'product N',
-
'username' => 'user N',
-
'country' => 'country N'
-
)
-
)
-
);
Then you would only have a single variable, "products", available in your template, which would essentially be a table of products, each element representing a data row.
In a Smarty template, you could use that as: - {foreach from=$products item=product}
-
<p>
-
Title: {$product.title}<br>
-
User : {$product.username}<br>
-
Country: {$product.country}
-
</p>
-
{/foreach}
thank you sir. I am trying it right now. will confirm as soon as I implement it
oh and just for info,im using the phplib template
if you google it its the first link.But Im trying to figure it out myself.thank you again
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert |
last post by:
I have a php/mysql query working like so:
$Query = "SELECT * FROM $TableName WHERE name LIKE '%".$searchterm."%'
"
All I want to do now is sort them alphabetically. By using the above...
|
by: danubian |
last post by:
Hi,
I'm a newbie in php/mysql programming,really am.
I'm working on a web-site that allows registration and posterior
logging in. Already registered user logs in with valid username and...
|
by: Jim Moseby |
last post by:
I stumbled across this while trying to update a table with a timestamp type column. At the time, I didn't know that the timstamp column would update itself when a row was changed. A kind gentleman...
|
by: Guy Erez |
last post by:
Hi,
I'm running queries with MySql 4.0.17 that return thousands of
records. Because I need to present them in GUI, I returieve the
results in chunks using LIMIT, for example - get first 100,...
|
by: Gnurp Gnarp |
last post by:
When the number of columns get large, it becomes increasingly
difficult to view the results of a select in a small window (e.g. 80
line xterm) because of line wrapping. Can I have the results of...
|
by: James |
last post by:
Hey everyone, I have a really obscure but impassable problem with a
reasonably simple piece of php/PEAR DB/MySQL code
When calling several stored procs the first call succeeds, but
subsequent...
|
by: SC |
last post by:
I'm developing a site that may eventually have a very large database of
users (hopefully, but who knows). It will be a community website where
users can search each other (think Friendster,...
|
by: ameshkin |
last post by:
I know this is probably not too hard to do, but how do I display
multiple rows of a mysql query/recordset. Im having trouble doing
this. I don't just want to display them, but I want to make sure...
|
by: taras.di |
last post by:
Hi everyone,
I've come across an extremely strange problem. The exact same query in
both mysql command line client, and mysql query browser gives entirely
different results. I was hoping someone...
|
by: PHPBABY3 |
last post by:
Hi,
1. I have two SQL tables. I will call them employees and departments:
EMP: LAST_NAME, FIRST_NAME, DEPTNM
DEPT: NUM, NAME
Input: text string FIND
Output: the LAST_NAME, FIRST_NAME...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |