need help
Moderator: General Moderators
need help
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
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
- novice4eva
- Forum Contributor
- Posts: 327
- Joined: Thu Mar 29, 2007 3:48 am
- Location: Nepal
Re: need help
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
but i need the code for html as this is for website
Re: need help
Maybe my eyesight is getting worse, but that's exactly what novice4eva gave you.ganza wrote:but i need the code for html as this is for website
Re: need help
ok now im added a delete button on the table
so it will be like this
how can i make an if statement so if i press delete. the data on mysql will be deleted?
thanks
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>';
thanks
Re: need help
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
i dont really get it what do you meanpapa 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.
is it possible for you to give the sample code? because im just start learning php and im so confused
Re: need help
First, add a hidden form field to your form:
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
<input type="hidden" name="contact_ID" value="<?php echo $data['contact_ID']; ?>">
Quick example:
Code: Select all
if(isset($_POST['delContact'])) {
//delete query
}