|
-
Here's the problem, I have two usernames, both of which are being called and stored in the variable $username, but for some reason, only one is being printed.
Code:
<?php
//just get the all the user's names from the username column
$sql="SELECT username FROM useradmins";
//connect to db, etc.
include("connect.php");
//while there exists a username in the array, run this code
while($row=mysql_fetch_array($sql_result))
{
//set the variable $username to hold the username value that was in the mysql column
$username=$row["username"];
//call the script that then takes the username variable and prints it out
include("featured.php");
print "<br>";
}
?>
While there are 2 usernames, only one gets printed. Any thoughts?
-
Hi,
I am sure you hve already tried to just print $username, so the problem might lie in featured.php. May I see it?
Musicman
-
okay
I may have oversimplified things in the previous post. Basically, I'm setting up a script that loads 'featured' editors data. You can see the output here:
http://www.inflash.com/showplayer/testindex.php
It is currently only displaying one editor when there are 3, all with publish=1
[code]
<?php
$sql="SELECT username, website, picurl, websitetitle FROM useradmins WHERE publish=1";
//connect db
include("connect.php");
while($row=mysql_fetch_array($sql_result))
{
$username=$row["username"];
$website=$row["website"];
$picurl=$row["picurl"];
$websitetitle=$row["websitetitle"];
include("testfeatured.php");
print "<br>";
}
?>
in testfeatured.php is contained:
Code:
<?php
print "<table>
<tr>
<td align=center colspan=4><font face=Verdana size=2><b>$username's Picks</b></a><br>";
if(isset($website))
{
print "<font face=Verdana><a href=$website>$websitetitle</a></font>";
}
print "</td><td colspan=2>";
if(isset($picurl))
{
print "<img src=$picurl border=1>";
}
etc.
here's the data (all test data) contained in the useradmins table (sorry it's not in alignment):
If you need the full scripts, let me know and I'll email them to you. It's got me stumped.
-
Hi mbannonb,
I changed script to fit my system (postgresql rather than mysql) and got three users rather than one.
One thing looks somewhat different - the xx_fetch_array code. Probably check this one in ph/mysql manual
Code:
<?php
$sql="SELECT username, website, picurl, websitetitle FROM useradmins WHERE publish=1";
$myDB = pg_connect("dbname=notenversand");
$sql_result = pg_exec($myDB, $sql);
$nrow = 0;
while($row=@pg_fetch_array($sql_result, $nrow++))
{
$username=$row["username"];
$website=$row["website"];
$picurl=$row["picurl"];
$websitetitle=$row["websitetitle"];
include("testfeatured.php");
print "<br>";
}
?>
Musicman
-
okay
First of all, thanks so much for your help.
I put the selected code above up on my server (for mysql) and it was working fine as well, but it wasn't working when combined with the whole script.
So, I figured it was something with the rest of the script. The problem was, I was fixated on the $username variable, thinking that it was the culprit. Why I stuck on that, I don't know.
But it turns out it was the $sql_result variable that was causing the problem.
The line: while($row=mysql_fetch_array($sql_result))
occurs in index.php, and then index.php calls featured.php, which also has
while($row=mysql_fetch_array($sql_result))
Thus, '$sql_result' gets looped through until it's empty. When it returns to 'index.php', '$sql_result' is empty, so when it revisits 'while($row=mysql_fetch_array($sql_result))', it's considered empty and the loop is terminated, even though only one username's data has been processed.
So there it is.
-
Hi,
you are right on that ... but this piece of code did not shine up on your post.
Anyway, it is interesting to see that some of the more common functions look different for different databases, although it was probably a major concern in php development to make them as similar as possible
Musicman
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|