Jump to content

PHP script modification. Need help. Thank you!


bchandel

Recommended Posts

I have the following script out put from which can be seen at

 

http://chandel.com/try.php

 

How can I modify this script to display:

 

1. Results: Number of records found

 

2. one record per page and then to put Next and Previous text to navigate Back and Forth for navigation

 

<html>

<body>

<?php

$db_connect = mysql_connect("xxxx.com", "xxxx_user", "password");

mysql_select_db("xxxx_database");

$query="SELECT * FROM Directory";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

 

print "<h1><center>My Directory</center></h1><br>";

$i=0;

while ($i < $num) {

 

$Name=mysql_result($result,$i,"Name");

$LastName=mysql_result($result,$i,"LastName");

$FirstName=mysql_result($result,$i,"FirstName");

$Phone=mysql_result($result,$i,"Phone");

$Mobile=mysql_result($result,$i,"Mobile");

$Email=mysql_result($result,$i,"Email");

$Web=mysql_result($result,$i,"Web");

$State=mysql_result($result,$i,"State");

$Country=mysql_result($result,$i,"Country");

 

echo "<b>$Name</b><br>

FirstName: $FirstName<br>

Home Phone: $Phone<br>

Mobile: $Mobile<br>

Email: $Email<br>

Web Site: $Web<br>

State: $State<br>

Country:$Country<br><hr><br>";

 

$i++;

}

 

?>

</body>

</head>

Thank you for your quick help. What $num=mysql_numrows($result); is doing in this script. Can i change as below to make it work? Look where I added:

 

echo "Search Results: mysql_num_rows($result); found

 

 

<html>

<body>

<?php

$db_connect = mysql_connect("xxxx.com", "xxxx_user", "password");

mysql_select_db("xxxx_database");

$query="SELECT * FROM Directory";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

 

print "<h1><center>My Directory</center></h1><br>";

$i=0;

while ($i < $num) {

 

echo "Search Results: mysql_num_rows($result); found

 

$Name=mysql_result($result,$i,"Name");

$LastName=mysql_result($result,$i,"LastName");

$FirstName=mysql_result($result,$i,"FirstName");

$Phone=mysql_result($result,$i,"Phone");

$Mobile=mysql_result($result,$i,"Mobile");

$Email=mysql_result($result,$i,"Email");

$Web=mysql_result($result,$i,"Web");

$State=mysql_result($result,$i,"State");

$Country=mysql_result($result,$i,"Country");

 

echo "<b>$Name</b><br>

FirstName: $FirstName<br>

Home Phone: $Phone<br>

Mobile: $Mobile<br>

Email: $Email<br>

Web Site: $Web<br>

State: $State<br>

Country:$Country<br><hr><br>";

 

$i++;

}

 

?>

</body>

</head>

 

 

 

 

 

 

if you are going to do that...

 

<html>
<body>
<?php
$db_connect = mysql_connect("xxxx.com", "xxxx_user", "password");
mysql_select_db("xxxx_database");
$query="SELECT * FROM Directory";
$result=mysql_query($query);
$num=mysql_num_rows($result); // CHANGE IT HERE
mysql_close();

print "<h1><center>My Directory</center></h1><br>";
$i=0;
while ($i < $num) {

echo "Search Results: $num found";  // CHANGE HERE

$Name=mysql_result($result,$i,"Name");
$LastName=mysql_result($result,$i,"LastName");
$FirstName=mysql_result($result,$i,"FirstName");
$Phone=mysql_result($result,$i,"Phone");
$Mobile=mysql_result($result,$i,"Mobile");
$Email=mysql_result($result,$i,"Email");
$Web=mysql_result($result,$i,"Web");
$State=mysql_result($result,$i,"State");
$Country=mysql_result($result,$i,"Country");

echo "<b>$Name</b><br>
FirstName: $FirstName<br>
Home Phone: $Phone<br>
Mobile: $Mobile<br>
Email: $Email<br>
Web Site: $Web<br>
State: $State<br>
Country:$Country<br><hr><br>";

$i++;
}

?>
</body>
</head> 

Thank you very much for your help. With some modifications the script is working good. You can see display from the script at

 

http://chandel.com/try/try3.php

 

What do I need to do if I only want to show one result on one page and want to put next and previous pagination on the bottom for easy navigation of the results.

 

Thank you much!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.