smc Posted January 24, 2007 Share Posted January 24, 2007 Heya,Alright basically I'm trying to create a listing of my usernames in the database. This is the code I am working with:[code=php:0]//Lets go ahead and connect to the DB using my fancy patent pending function (saves time doesn't it)dbconnect();//The following will execute a query to list all the users//Query for execution//$fetchfido = mysql_query("SELECT * FROM users ORDER BY username ASC");$fetchfido = mysql_query('SELECT * FROM `users` ORDER BY `users` . `username` ASC');//While we are grabbing the array we will go ahead and prep the HTML for echoingwhile($users = mysql_fetch_array($fetchfido)){ $listusers = "<a href=\"admin.php?user=$users[username]\">$users[username]</a><br />"; $cms_template_path = '../templates/admin/'; require($cms_template_path . 'admin_users.php'); die;}[/code]My problem is with the code above it only lists the first username and then stops. I tried taking out the die; function and it listed all the usernames, but also included a new template for every single specific username.How can I get around this problem? Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/ Share on other sites More sharing options...
Caesar Posted January 24, 2007 Share Posted January 24, 2007 Why are you executing the "die" function in your loop? Just curious. ;) You're basically terminating your script after it outputs the first record.Edit: Not sure what your template include is doing....but why not do the include outside of the loop? Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168393 Share on other sites More sharing options...
smc Posted January 24, 2007 Author Share Posted January 24, 2007 Because I want it to stop executing everything beneath that particular block of code Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168395 Share on other sites More sharing options...
craygo Posted January 24, 2007 Share Posted January 24, 2007 your sql statement may not be right[code]$fetchfido = "SELECT * FROM `users` ORDER BY username ASC";[/code]Also set the template path before the loop. not need to set it for every user in the table.What is in the admin_users.php file???The die function wil cause the loop to end the first time it runs through. Take it out and put the die after the loop.Ray Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168397 Share on other sites More sharing options...
The Little Guy Posted January 24, 2007 Share Posted January 24, 2007 wouldn't die look like this:die(); Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168399 Share on other sites More sharing options...
smc Posted January 24, 2007 Author Share Posted January 24, 2007 [quote author=craygo link=topic=123881.msg512617#msg512617 date=1169670807]your sql statement may not be right[code]$fetchfido = "SELECT * FROM `users` ORDER BY username ASC";[/code]Also set the template path before the loop. not need to set it for every user in the table.What is in the admin_users.php file???The die function wil cause the loop to end the first time it runs through. Take it out and put the die after the loop.Ray[/quote]The admin_users.php file is the template file for admin_users.php script (both in different folders). admin_users.php template only has <? echo $listusers; ?>And my problem is if I take die out then it will keep running and running, creating a template for every single user. If I put the require and die after the while script then it only shows the last user to be called in the array Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168409 Share on other sites More sharing options...
craygo Posted January 24, 2007 Share Posted January 24, 2007 Not to go around your problem here, but why would you call another file to echo our your results??[code]<?php$sql = "SELECT * FROM `users` ORDER BY username ASC";$fetchfido = mysql_query($sql) or die(mysql_error());while($users = mysql_fetch_array($fetchfido)){ echo "<a href=\"admin.php?user=".$users[username]."\">".$users[username]."</a><br />";}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168416 Share on other sites More sharing options...
smc Posted January 24, 2007 Author Share Posted January 24, 2007 Because I want to put it in my style template to make it look nice. My PHP and Template files are completly seperate. Putting PHP integrated into HTML just causes to many mistakes, for me at least. Link to comment https://forums.phpfreaks.com/topic/35565-fetch-array-problem/#findComment-168505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.