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
Icethrill
Forum Newbie
Posts: 13 Joined: Fri Jan 02, 2009 9:55 am
Post
by Icethrill » Tue Feb 03, 2009 3:49 am
The thing is I am retrieving information from a database, it makes a list of all INACTIVE links that needs to be accepted by a admin. Down at the foreach its a very confusing code, its just me testing things out. I need a push in the right direction, dont wanna have more problems with this. Well anyways I want the links to be accepted through a checkbox. I want it to be able to pass multiple links that I want to make active. I only know a way of making 1 active. Anyone who can help me out?
Code: Select all
<?php
$query = 'SELECT * FROM url_list WHERE url_status = 0 ORDER BY url_kategori ASC';
$result = mysql_query($query);
confirm_query($result);
echo "<form method='post' action=''>";
while($url = mysql_fetch_array($result))
{
echo "<h3>Kategori: " . $url['url_kategori'] . "</h3>";
echo "<p>Titel: " . $url['url_titel'] . "</p>";
echo "<a href=" . $url['url_url'] . ">" . $url['url_url'] . "</a><br />";
echo "<p>Beskrivning: " . $url['url_beskrivning'] . "</p>";
echo "<label>Godkänn länk</label><input type=\"checkbox\" name=" . $url['url_id'] . " value='1' /><br />";
}
echo "<input type=\"submit\" name=\"updateurl\" />";
echo "</form>";
if(isset($_POST['updateurl']))
{
foreach($url['url_id'] as $id)
{
$query = "UPDATE SET url_status = " . $_POST['$url['url_id']'] . " WHERE url_id = {$id}";
$result = mysql_query($query);
confirm_query($result);
}
}
?>
mickeyunderscore
Forum Contributor
Posts: 129 Joined: Sat Jan 31, 2009 9:00 am
Location: UK
Post
by mickeyunderscore » Tue Feb 03, 2009 4:46 am
The code looks close to working, I think you just need a small modification:
Code: Select all
<?php
$query = 'SELECT * FROM url_list WHERE url_status = 0 ORDER BY url_kategori ASC';
$result = mysql_query($query);
confirm_query($result);
echo "<form method='post' action=''>";
while($url = mysql_fetch_array($result))
{
echo "<h3>Kategori: " . $url['url_kategori'] . "</h3>";
echo "<p>Titel: " . $url['url_titel'] . "</p>";
echo "<a href=" . $url['url_url'] . ">" . $url['url_url'] . "</a><br />";
echo "<p>Beskrivning: " . $url['url_beskrivning'] . "</p>";
echo "<label>Godkänn länk</label><input type=\"checkbox\" name=" . $url['url_id'] . " value='1' /><br />";
$inactive_links[] = $url;
}
echo "<input type=\"submit\" name=\"updateurl\" />";
echo "</form>";
if(isset($_POST['updateurl']))
{
for($i = 0, $c = count($inactive_links); $i < $c; $i++)
{
if(!$_POST[$inactive_links[$i]['url_id']]){
continue;
}
$query = "UPDATE SET url_status = " . $_POST[$inactive_links[$i]['url_id']] . " WHERE url_id = ".$inactive_links[$i]['url_id']."";
$result = mysql_query($query);
confirm_query($result);
}
}
?>
That should work for you, though I haven't tested it.
Icethrill
Forum Newbie
Posts: 13 Joined: Fri Jan 02, 2009 9:55 am
Post
by Icethrill » Tue Feb 03, 2009 6:02 am
thanks it worked after I tweaked it a little