light-angel Posted January 2, 2008 Share Posted January 2, 2008 hi i have made a script what is all reading out of a sql databace right now after hours lol well this is what i need help with i have EG test address name 1 <address here> <name of test> 2 <address here> <name of test> but my PHP page only will ready line 1 and then wont go down and show line 2 i have about 10 lines i need to do can anyone help me plz Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/ Share on other sites More sharing options...
phorcon3 Posted January 2, 2008 Share Posted January 2, 2008 $a = mysql_query("SELECT * FROM `your_table` WHERE `this` = 'that' ORDER BY `test` LIMIT 0,10"); while($b = mysql_fetch_array($a, MYSQL_ASSOC)) { echo '<div>Address: '.$b['address'].'</div><div>Name: '.$b['name'].'</div>'; } is that what u were lookin for? Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-427731 Share on other sites More sharing options...
light-angel Posted January 2, 2008 Author Share Posted January 2, 2008 this is what i have so far i need it to go from the first one onto the next one getting the info from each line if thats anymore help <? $username="xxxxxxx"; $password="xxxxxxxxx"; $database="xxxxxxxxxxxxxxxxxxxxxxx"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM hubs"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $hub=mysql_result($result,$i,"hub"); $hubname=mysql_result($result,$i,"hubname"); $address=mysql_result($result,$i,"address"); $port=mysql_result($result,$i,"port"); $owner=mysql_result($result,$i,"owner"); $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-427732 Share on other sites More sharing options...
phorcon3 Posted January 2, 2008 Share Posted January 2, 2008 php file: <?php $username = ''; $password = ''; $database = ''; $host = 'localhost'; if(!mysql_select_db($database, mysql_connect($host, $username, $password))) { die('Couldn\'t connect to the database. The following error occurred: '.mysql_error().'');exit; } $a = mysql_query("SELECT * FROM `hubs` WHERE `id` != '' ORDER BY `id` DESC"); while($b = mysql_fetch_assoc($a)) { echo '<div>ID#: '.$b['hub'].'</div>'; echo '<div>Name: '.$b['hubname'].'</div>'; echo '<div>Address: '.$b['address'].'</div>'; echo '<div>Port: '.$b['port'].'</div>'; echo '<div>Owner: '.$b['owner'].'</div>'; } ?> sql file should look like this: CREATE TABLE `hubs` ( `hub` int(11) NOT NULL auto_increment, `hubname` varchar(225) NOT NULL default '', `address` varchar(225) NOT NULL default '', `port` varchar(225) NOT NULL default '', `owner` varchar(225) NOT NULL default '', `time` int(11) NOT NULL default '0', PRIMARY KEY (`hub`) ) TYPE=MyISAM AUTO_INCREMENT=1; hope this works;) Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-427742 Share on other sites More sharing options...
phorcon3 Posted January 2, 2008 Share Posted January 2, 2008 oops, got somethin wrong: <?php $a = mysql_query("SELECT * FROM `hubs` WHERE `id` != '' ORDER BY `id` DESC"); while($b = mysql_fetch_assoc($a)) ?> should be <?php $a = mysql_query("SELECT * FROM `hubs` WHERE `hub` != '' ORDER BY `hub` DESC"); while($b = mysql_fetch_assoc($a)) ?> Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-427743 Share on other sites More sharing options...
light-angel Posted January 2, 2008 Author Share Posted January 2, 2008 this is the config script <? $username="xxxxxxxxxx"; $password="1234"; $database="xxxxxxxxxxxxxx"; if(!mysql_select_db($database, mysql_connect($host, $username, $password))) { die('Couldn\'t connect to the database. The following error occurred: '.mysql_error().'');exit; } $a = mysql_query("SELECT * FROM `hubs` WHERE `id` != '' ORDER BY `id` DESC"); while($b = mysql_fetch_assoc($a)) { echo '<div>ID#: '.$b['hub'].'</div>'; echo '<div>Name: '.$b['hubname'].'</div>'; echo '<div>Address: '.$b['address'].'</div>'; echo '<div>Port: '.$b['port'].'</div>'; echo '<div>Owner: '.$b['owner'].'</div>'; } ?> <?php $b['hub'] = @fsockopen("$b['address']","$b['port']", $errno, $errstr, 2); if($hub1) { $hub1=true; } else { $hub1=false; } ?> <?php $b['hub'] = @fsockopen("$b['address']", "$b['port']", $errno, $errstr, 2); if($hub2) { $hub2=true; } else { $hub2=false; } ?> and this is the page im wanting it to go to <style type="text/css"> <!-- .style1 {color: #D9FFB3} .style2 {color: #FFC6C6} body { background-color: #999999; } --> </style> <div align="center"> <table width="486" border="1"> <tr> <td width="57"><b>Name:</b></td> <td width="140"><div align="center"><?php echo $hubname ?></div></td> <td width="57"><b>DNS:</b></td> <td width="241"><div align="center"><a href='dchub://the-tardis.no-ip.com:2411'> the-tardis.no-ip.com:2411</a></div></td> </tr> <tr> <td><b>Owner:</b></td> <td><div align="center"><?php echo $owner ?></div></td> <td><b>Stats:</b></td> <td><div align="center"> <?php if($hub) { ?> <span class="style1">Online</span> <?php } else { ?> <span class="style2">Offline</span><?php } ?> </td> </tr> </table> <br /> <table width="486" border="1"> <tr> <td width="57"><b>Name:</b></td> <td width="140"><div align="center"><?php echo $hubname ?></div></td> <td width="57"><b>DNS:</b></td> <td width="241"><div align="center"><a href='dchub://ukmusic.no-ip.com:420'>ukmusic.no-ip.com:420</a><a href='dchub://the-tardis.no-ip.com:2411"'></a></div></td> </tr> <tr> <td><b>Owner:</b></td> <td><div align="center"><?php echo $owner ?></div></td> <td><b>Stats:</b></td> <td><div align="center"> <?php if($hub) { ?> <span class="style1">Online</span> <?php } else { ?> <span class="style2">Offline</span><?php } ?> </div></td> </tr> </table> <br /> </div> <p> </p> <div align="center"><?php echo $myString; ?></div> Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-427762 Share on other sites More sharing options...
light-angel Posted January 2, 2008 Author Share Posted January 2, 2008 bump Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-428208 Share on other sites More sharing options...
adam291086 Posted January 2, 2008 Share Posted January 2, 2008 can you descibe your current problem Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-428211 Share on other sites More sharing options...
aschk Posted January 2, 2008 Share Posted January 2, 2008 The solution was given to you... read it Quote Link to comment https://forums.phpfreaks.com/topic/84038-solved-sql-and-php-autoincrease/#findComment-428212 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.