how to retrieve from database for diff page using 1 php?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xiao_dolp
Forum Newbie
Posts: 15
Joined: Sun Jul 01, 2007 7:00 am

how to retrieve from database for diff page using 1 php?

Post by xiao_dolp »

hi!!
now i using one php file to echo out from database for most of my different page when i select from the menu. and i assign different id to different info. but the information in database is by inserting inside.

now i want to create a html in same page with box to insert the information and let it add on to my database and display today.

but i not sure how to make it into my database and let different page just display the information that shd be on the page

for example if i select Bp and insert information on the box, the information shd oni display in Bp and not other page



This is my part of my main code

Code: Select all

<?php

require('db.php');

mysql_connect(MACHINE, USER, '');
mysql_select_db(DBNAME);

$id = $_POST['id'];
$from = $_POST['from'];
$where = $_POST['where'];
$to = $_POST['to'];
$description = $_POST['description'];

$sql = "INSERT INTO where ( 'id', 'from', 'where', 'to', 'description')VALUES ( 'NULL', '$from', '$where', '$to',  '$description')";

$menu = (int) @$_POST['menu'];

$sql = "SELECT * FROM where WHERE id = $menu"; 


$res = mysql_query($sql) or die(mysql_error());
//$row = mysql_fetch_array($res);
while($row = mysql_fetch_array($res)){
echo "<tr>";
echo "<td>";
echo "From" . "&nbsp;" . $row[from]. "," . "&nbsp;";
echo "Please" . "<BR>" . $row[route];
echo "&nbsp;" . "to" . "&nbsp;" . $row[to];
echo "<BR>" . $row[description], ".";
echo "</table>";
}
?>


    <h3>Feel free to add!!!</h3>
    <h3>&nbsp;</h3>
    <h3> Route:<br />
        <textarea name="where" cols="50" rows="5" height="55"></textarea>
        <br />
        <p> </p>
    </h3>
    <h3>Description:<br />
        <textarea name="description" cols="50" rows="5" height="55"></textarea>
        <br />
        <br />
        <input type="submit" value="Submit" name='sub' />
    </h3>
<p class="style2">Where you want: </p>
 Please select 
           <form name="jump" action="where.php" method="post">
			
  
  <select name="menu" size="3">
      <option value="1">Bp</option>
    <option value="2">S</option>
<option value="3">CT</option>
<option value="4">BG</option>

  </select>
  <input type="submit" value="GO">
</p>
do anyone know how???
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I am having a really hard time following your question. Can you explain it a little differently perhaps?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

Im taking a wild guess from the couple sentences i could read.

index.php?id=2

Code: Select all

print $_GET['id'];

Code: Select all

2
xiao_dolp
Forum Newbie
Posts: 15
Joined: Sun Jul 01, 2007 7:00 am

Post by xiao_dolp »

ok, no problem, i try to explain it again

[s]coz[/s] because previously, i insert my database in the xampp manually.

now i create a box in the page itself so that i can just type in from there and let it display on the page itself.

but i [s]oni[/s] only use 1 php file which is where.php to display all the information from the [s]databse[/s] database, but i have many page like bk.php or s.php.
as in the [s]databse[/s] database i assign each row with a id.

for example when i choose [s]bk[/s] back [s]frm[/s] from the menu, it will go to where.php to call out [s]oni[/s] only [s]bk[/s] back info, when i choose s, it will aso go where.php but [s]oni[/s] only cal the s info.

so i want to ask, if i have the box in where.php to type the data itself, and i want to insert data for bk, how to call it in where.php???

[s]cn[/s] can understand or need me to explain by pic?
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Basically you need a textarea that you can enter text into (like you do in these forums) that when you hit the submit button, the data gets stored in the database and is seen next time the page loads? Is that right?
xiao_dolp
Forum Newbie
Posts: 15
Joined: Sun Jul 01, 2007 7:00 am

Post by xiao_dolp »

ya!
and i have the textarea in the page

Code: Select all

<h3>Feel free to add!!!</h3>
    <h3>&nbsp;</h3>
    <h3> Route:<br />
        <textarea name="where" cols="50" rows="5" height="55"></textarea>
        <br />
        <p> </p>
    </h3>
    <h3>Description:<br />
        <textarea name="description" cols="50" rows="5" height="55"></textarea>
        <br />
        <br />
        <input type="submit" value="Submit" name='sub' />
    </h3>
so how to insert the thing i have type in the same databse as what i manually insert in the xampp if every information in the database contain a id???

for example S is id 1, and i wan to add infor for id 1 oni but nt the other wan by using where.php??
Post Reply