Php Coding
#1
Posted 08 March 2006 - 03:49 AM
i can retrieve the data but the data cant diplay inside the dropdown menu.....n i need the the code tat can inside new data n display there....who can help me ....coz i'm a new user for php......THANKS YOU.......
#2
Posted 08 March 2006 - 09:01 AM
-Devyn
#3
Posted 08 March 2006 - 11:01 AM
http://www.pixel2life.com/forums/index.php...=%26lt%3Bselect
The second part, i just don't understand, could you explain it a bit better please?
#4
Posted 08 March 2006 - 11:31 PM
<?PHP
$table = 'TABLE HERE';
$check = mysql_query("SELECT `*` FROM `$table`") or die(mysql_error());
echo '<select name = "name">
<option value = "">-Please Select One-</option>';
while ($r = mysql_fetch_array($check, MYSQL_NUM))
{
echo '<option value = "' . $r[0] . '">' . $r[1] . '</option>';
}
echo '</select>';
?>
Ok, that is a standard version, usually when you are gaining from a db $r[0] is the ID so whats what I gained for that and $r[1] would be the text you want displayed.Please Note: This was just a snippet of an example, it most likely will needed to be edited to your settings. If this is begining put into a php code that already exists remove the <?PHP and ?>
Edited by liveman, 08 March 2006 - 11:32 PM.
#5
Posted 10 March 2006 - 06:09 AM
now is another problem that need help....i think is the last past of my project already......
i need to display all my data in the database...n only display 10 data per page...so that i need a NEXT and PREV button to display the NEXT 10 data n go back to the PREV data....i done some calculation but only the NEXT N PREV part i can link n i cant display the NEXT 10 data.....
i think i can post my coding here n somebody can help me debug......
**************************
MY CODING IS HERE
**************************
<?php
static $page = 1;
$connection = mysql_connect("localhost", "root", "root");
$db ="lee-ass";
mysql_select_db($db, $connection)or
die("Could not open $db");
$limit = 10;
$query_count = "SELECT count(*) FROM companydata";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM companydata LIMIT $limitvalue, $limit";
$result = mysql_query($query) or
die("Count not execute sql: $query");
$PHP_SELF = 'Testing.php';
echo '<h2 align=center>Company Data</h2>';
echo '<hr/>';
echo '<table align=center border="1" height="250" width="950">';
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo "<a href=\"UpdateInfo.php?Number=$result\">";
echo "<img src=\"..\Lee-Ass\update.bmp\" alt=\"View Infomation\" border=\"0\">";
echo "</td><td>";
echo $row["CoName"];
echo '</td><td>';
echo $row["Category"];
echo '</td><td>';
echo $row["Address"];
echo '</td><td>';
echo $row["Contact1"];
echo '</td><td>';
echo "<a href=\"DeleteInfo.php?Number=$result\">";
echo '<img src="..\Lee-Ass\delete.bmp" alt="View Infomation" border="0">';
echo "</a></td></tr>";
}
echo '</table>';
if($page == 1){
$pageprev = $page--;
echo "<a href=\"$PHP_SELF&page=$pageprev\">PREV" .$limit. "</a>";
}else{
echo "<center>PREV</center>";
}
echo $page;
if (($totalrows - ($limit * $page)) > 0) {
$pagenext = $page++;
echo "<a href=\"$PHP_SELF?page=$pagenext\">NEXT" .$limit. "</a>";
}else {
echo "<center>NEXT</center>";
}
mysql_free_result($result);
?>
***************************************************************
i think tat i need a STATIC on top of the page......how i want to run loop on this page....
so anyone can help me .......
i cant run the NEXT and PREV function....
***************************************************************
****************************************************************
#6
Posted 10 March 2006 - 07:13 AM
<?PHP
if(empty$limit))
{
$limit = 0;
}
$check = mysql_query("SELECT * FROM `TABLE` LIMIT $limit, 10") or die(mysql_error());
?>
After that put the following code for the links
<?PHP $newlimtadd = $_GET['limit'] + 10; $newlimtsub = $_GET['limit'] - 10; echo "<a href = 'page.php?limit=$newlimitsub&do=true'>Prev. Page</a>"; echo "<a href = "page.php?limit=$newlimitadd&do=false'>Next Page</a>"; ?>
#7
Posted 11 March 2006 - 01:10 AM
can anyone write the full coding for me
my database name is "lee-ass"
table is "companydata"
per rows got this data "Number, CoName, Address";
Edited by ypsmag, 11 March 2006 - 01:18 AM.
#8
Posted 12 March 2006 - 01:05 PM
<?
// Change this information below to fit your needs
$db = 'lee-ass';
$dbhost = 'localhost';
$dbuser ='';
$dbpass = '';
$table = 'companydata';
$pageurl = ''; // DO NOT ADD HTTP://
// Now let us get to work
mysql_connect($dbhost,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
if(empty($limit) and empty($_GET['limit']))
{
$limit = 0;
}
else
{
$limit = $_GET['limit'];
}
$check = mysql_query("SELECT `Number`, `CoName`, `Address` FROM `$table` LIMIT $limit, 10") or die(mysql_error());
$num = mysql_num_rows($check);
if($num == '0')
{
echo '<font color = "red"><b><center>Currently no information in database!</center></b></font>';
}
else
{
echo '<table border = "0">
<tR>
<td>Number</td>
<td>CoName</td>
<td>Address</td>
</tr>';
while($r = mysql_fetch_rows($check, MYSQL_NUM))
{
echo '
<tr>
<Td>' . $r[0] . '</td>
<td>' . $r[1] . '</td>
<Td>' . $r[2] . '</td>
</tr>
';
}
echo '</table>';
$newlimtsub = $_GET['limit'] - 3;
$newlimtadd = $_GET['limit'] + 3;
echo "<A href = 'java script: history.go(-1)'>Prev Page</a>";
if($newlimtadd > $num)
{
echo '';
} else {
echo " | <A href = 'Http://' . $pageurl . '&limit=$newlimtadd'>Next Page</a>";
}
}
?>
Edited by liveman, 12 March 2006 - 01:06 PM.
#9
Posted 12 March 2006 - 08:39 PM
got some problem in the......
when i run this page, the internet browser will come out the problem for this 2 thing.......
This is the error notice come out from the internet browser.....
//Fatal error: Call to undefined function mysql_fetch_rows()//
while($r = mysql_fetch_rows($check, MYSQL_NUM))......
and this
Undefined index: limit
Edit:
Thanks Little Yoda.....
i done it already....
Thanks a lot........
but i think next project still need your help...haha.......
Little Yoda can we be a friends.....
Actually where are you from???
I'm Malaysian......
Edited by ypsmag, 12 March 2006 - 08:42 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
