need help

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
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

need help

Post 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
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: need help

Post 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>';
 
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

Re: need help

Post by ganza »

but i need the code for html as this is for website
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: need help

Post 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.
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

Re: need help

Post 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
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

Re: need help

Post by ganza »

need helppppp :banghead:
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: need help

Post 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.
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

Re: need help

Post 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:
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: need help

Post 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
}
 
Post Reply