Jump to content

[SOLVED] sql and php autoincrease


light-angel

Recommended Posts

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

Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

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++;

}

 

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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>

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.