Page 1 of 1

need help

Posted: Fri Nov 07, 2008 4:01 am
by ganza
hi all,

i need help for php code.
first i read the table from the mysql and i print the array
the array is like this:
Array
(
[0] => Array
(
[contact_ID] => 00000000000000000001
[client_ID] => 00000000000000000002
[personIncharge] => sadfsadf
[designation] => asdfasdfasdfasd
[department] => asdfasdfasd
[mainLine] => asdfsadf
[faxLine] => asdfasdf
[directLine] => asdfsadf
[mobile] =>
)

[1] => Array
(
[contact_ID] => 00000000000000000002
[client_ID] => 00000000000000000002
[personIncharge] => sadfasdf
[designation] => fasdfasdf
[department] => sadfasd
[mainLine] => asdfasdf
[faxLine] => asdfasdfads
[directLine] => asdfasdf
[mobile] => fasdfsadfdsaf
)

)

this is the code that i've done:
if(isset($_REQUEST["Submit"]) == true){
$contactList = "SELECT * FROM contact WHERE client_ID = ('".$_REQUEST["client_ID"]."')";
$db->sql_query($contactList);
$list = $db->sql_fetchrowset();
print_r($list);
}
is it possible for me to print array on $list in html?
how can i code it?

Thanks

Re: need help

Posted: Fri Nov 07, 2008 4:07 am
by novice4eva
let's say the array you generated is under the name $myArray.

Code: Select all

 
echo '<table>';
echo "<tr>";
echo "<td>Contact Id</td>";
echo "<td>Client Id</td>";
....
....
echo "<td>Mobile</td>";
echo "</tr>";
foreach($myArray as $data)
{
echo "<tr>";
echo "<td>".$data['contact_ID']."</td>";
echo "<td>".$data['client_ID']."</td>";
...
...
echo "<td>".$data['mobile']."</td>";
echo "</tr>";      
}
echo '</table>';
 

Re: need help

Posted: Fri Nov 07, 2008 4:27 am
by ganza
but i need the code for html as this is for website

Re: need help

Posted: Fri Nov 07, 2008 5:21 am
by requinix
ganza wrote:but i need the code for html as this is for website
Maybe my eyesight is getting worse, but that's exactly what novice4eva gave you.

Re: need help

Posted: Sun Nov 09, 2008 7:22 pm
by ganza
ok now im added a delete button on the table
so it will be like this

Code: Select all

 
    echo "<form id=\"delContact\" name=\"delContact\" method=\"post\" action=\"\">";
    echo '<table border=1>';
    echo "<tr>";
    echo "<td>Person in Charge</td>";
    echo "<td>Designation</td>";
    echo "<td>Department</td>";
    echo "<td>Main Line</td>";
    echo "<td>Fax Line</td>";
    echo "<td>Direct Line</td>";
    echo "<td>Mobile</td>";
    echo "</tr>";
    foreach($list as $data)
    {
    echo "<tr>";
    echo "<td>".$data['personIncharge']."</td>";
    echo "<td>".$data['designation']."</td>";
    echo "<td>".$data['department']."</td>";
    echo "<td>".$data['mainLine']."</td>";
    echo "<td>".$data['faxLine']."</td>";
    echo "<td>".$data['directLine']."</td>";
    echo "<td>".$data['mobile']."</td>";
    echo "<td>";
    echo "<input type=\"submit\" name=\"Delete\" value=\"Delete\">";
    echo "</td>";
    echo "</form>";
    echo "</tr>";      
    }
    echo '</table>';
 
how can i make an if statement so if i press delete. the data on mysql will be deleted?


thanks

Re: need help

Posted: Mon Nov 10, 2008 1:36 am
by ganza
need helppppp :banghead:

Re: need help

Posted: Mon Nov 10, 2008 2:41 am
by papa
Use add hidden field to store the id of the item. Then add an if statement that deletes the record where id = hidden post value.

Re: need help

Posted: Mon Nov 10, 2008 2:47 am
by ganza
papa wrote:Use add hidden field to store the id of the item. Then add an if statement that deletes the record where id = hidden post value.
i dont really get it what do you mean
is it possible for you to give the sample code? because im just start learning php and im so confused :crazy:

Re: need help

Posted: Mon Nov 10, 2008 4:55 am
by papa
First, add a hidden form field to your form:

Code: Select all

 
<input type="hidden" name="contact_ID" value="<?php echo $data['contact_ID']; ?>">
 
After that, you can create an if statement in PHP that executes a delete query using $data['contact_ID'] in where clause.

Quick example:

Code: Select all

 
if(isset($_POST['delContact'])) {
//delete query
}