Jump to content


Photo

how to retrieve values stored from database (mysql)


  • Please log in to reply
2 replies to this topic

#1 elie

elie
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 18 May 2006 - 02:21 PM

i have stored arrayed fields into the database... i want to create a new page where i can call and retrieve these values stored from the database? please help...

<?php
include("config.php");

$field_a = $_POST['field_a'];
$field_b = $_POST['field_b'];
$field_c = $_POST['field_c'];
$field_d = $_POST['field_d'];
$field_e = $_POST['field_e'];
$field_f = $_POST['field_f'];
$num = $_POST['num'];
foreach($field_a as $key => $val) 
{
$sql="INSERT INTO sample (field_a, field_b, field_c, field_d, field_e, field_f, code) VALUES 

('".$val."','".$field_b[$key]."','".$field_c[$key]."','".$field_d[$key]."','".$field_e[$key]."','".$field_f[$key]."','$code')";
mysql_query($sql) or die(mysql_error());
}

?>


#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 18 May 2006 - 02:25 PM

$query = "SELECT * FROM sample";
$result = mysql_query($query) or die(mysql_error());
if($result && mysql_num_rows($result) > 0)
{
     while($row = mysql_fetch_array($result))
     {
          extract($row);
          echo "$field_a<br />";
          echo "$field_b<br />";
          // etc
     }
}

Info: PHP Manual


#3 elie

elie
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 18 May 2006 - 03:37 PM

thanks for the help ober!! [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users