By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,251 Members | 2,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,251 IT Pros & Developers. It's quick & easy.

displaying data fetched from mysql

P: 59
Hi,

For my project I have a "add" button, upon clicking it, it will take the user to next page where there will be a text box and list of data displayed below it which is fetched from mysql database. I have written the code for this which is working fine. But I have a problem, i.e. when user enters the code in text box and clicks "go" button a group of data will be fetched from the database and should be displayed below the text box, where previously the mysql group of data was displayed i.e. the new group of data fetched from mysql database should replace the old group of data. I hope you got my point.

For eg, when the user clicks add link in pageone.php page he will send the nameid=2, and mysql data for this nameid will be fetched from mysql and displayed below the textbox in pageload.php page. But in pageload.php page the user will be having option to enter his own nameid and search results for that. So when he clicks the go button, mysql data for this nameid should be fetched and displayed in the place of previous data. There should not be 2 set of data displayed. How can I do this

How will I do this, please give me some idea

Here is the code I have written

pgaeone.php

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <a href="pageload.php?nameid=2">ADD</a> 
  4. </body>
  5. </html>

pageload.php

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form name="load" action="" method="POST">
  4. please enter code
  5. <input type="text" name="sel">
  6. <input type="submit" value="go" name="sub">
  7. </form>
  8. <?php
  9.     $id = $_GET['nameid'];
  10.  
  11.     $sql = "SELECT name FROM TEBLE1 WHERE nameid='$id'";
  12.     $result = mysql_query($sql);
  13.     while ($values = mysql_fetch_array($result))
  14.     {
  15.         echo $values['0'];
  16.         echo "<br>";  
  17.     }
  18.  
  19. ?>
  20. </body>
  21. </html>
Please help.


With regards
May 19 '08 #1
Share this Question
Share on Google+
1 Reply


TheServant
Expert 100+
P: 1,168
A few things, first, I think you are collecting something else. You have your form POSTing, and then your php is GETting. You have no action, so if you are POSTing I think you want to send the data to itself by using something like:
[php]action="<?php echo $_SERVER['REQUEST_URI']; ?>"[/php]
and then change your $id to $_POST['nameid'].

That brings me to my next point, where is "nameid" given? Your text input is called sel? So shouldn't your code have $id=$_GET['sel']?

If you don't have all your code and have addressed the above problems there, say so and we can move on. If you don't understand what I have asked/suggested, then let me know how much PHP you have done, so I can suggest some good tutorials.

For the fact that new lines are being added, I think it's because you have a while loop in there.

Try this:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <form name="load" action="" method="POST">
  4. please enter code
  5. <input type="text" name="sel">
  6. <input type="submit" value="go" name="sub">
  7. </form>
  8. <?php
  9.     $id = $_GET['nameid'];
  10.  
  11.     $sql = "SELECT name FROM TEBLE1 WHERE nameid='$id'";
  12.     $result = mysql_query($sql);
  13.     {
  14.         echo ( $result."<br />" ) ;
  15.     }
  16.  
  17. ?>
  18. </body>
  19. </html>
May 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.