Getting buttons and textboxes within loop
Moderator: General Moderators
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: Getting buttons and textboxes within loop
Hi Goofan
Could you explain what the problem is with your code now? Do you mean that its not displaying the correct values for the current quantity?
Also, could you give me a screenshot of the full table structure not just the last three columns - blank out anything you don't want to show but keep all the column names visible please?
I'll have a look through your code now and see if there's anything I can find wrong
also, not too sure why barakobama decided to copy and paste a part of one of my earlier replies, it makes no sense as a reply to your latest question so best to ignore it
Ian
Could you explain what the problem is with your code now? Do you mean that its not displaying the correct values for the current quantity?
Also, could you give me a screenshot of the full table structure not just the last three columns - blank out anything you don't want to show but keep all the column names visible please?
I'll have a look through your code now and see if there's anything I can find wrong
also, not too sure why barakobama decided to copy and paste a part of one of my earlier replies, it makes no sense as a reply to your latest question so best to ignore it
Ian
Re: Getting buttons and textboxes within loop
ok thats alot and will take some time but sure ill post all "php code is all i got" on the page...
and what was it that u wanted? the database?
and the design window?
tell me exactly what u want out and ill see what i can do =)
and what was it that u wanted? the database?
and the design window?
tell me exactly what u want out and ill see what i can do =)
Re: Getting buttons and textboxes within loop
Notice: Undefined variable: my in C:\Program Files\wamp\www\www\Projektarbete\sidor\Infanteries.php on line 95
i got this errro running now
line 95 is this:
i got this errro running now
line 95 is this:
Code: Select all
<th><?php echo $my[$row1['Units']]; ?></th>
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: Getting buttons and textboxes within loop
Well if you can, just a full list of columns and their datatypes for the two tables you're using. It's a bit difficult to work out from the screenshots exactly what data will be returned by each of your queries, which makes it a little difficult to work out whats going wrong.
Alternatively, you could replace the *'s in your queries with a full list of column names (usually better for yourself too, you can see easily what data you get back) and post your updated code.
Also could you be specific as to what the problem is. Your screenshot with the circles drawn on doesn't show whether thats what is happening or if thats what you'd like to happen, and it doesn't seem to reflect the data shown in another screenshot of the database table
if $my isn't defined then I'd assume your first mysql_query call isn't returning any results (hence $my is never set). check that query is returning results by running it in phpmyadmin or mysql query browser (from mysql.com)
Alternatively, you could replace the *'s in your queries with a full list of column names (usually better for yourself too, you can see easily what data you get back) and post your updated code.
Also could you be specific as to what the problem is. Your screenshot with the circles drawn on doesn't show whether thats what is happening or if thats what you'd like to happen, and it doesn't seem to reflect the data shown in another screenshot of the database table
if $my isn't defined then I'd assume your first mysql_query call isn't returning any results (hence $my is never set). check that query is returning results by running it in phpmyadmin or mysql query browser (from mysql.com)
Re: Getting buttons and textboxes within loop
MY COmplete text one paragraf!:
my datatable "konto" will be shown in the attatchments...
Code: Select all
<?php
// Get the database connector stuff
include "../login/database.php";
// Build our query
$sql1 = 'SELECT * FROM `infantries`';
// Get the result if there is one
// DO NOT die() IN PRODUCTION!!!
if (!$result1 = mysql_query($sql1))
{
die('The query<br /><strong>' . $sql1 . '</strong><br />failed:<br />' . mysql_error());
}
?>
<?php
$id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;
if($id !== false) {
$sql="SELECT * FROM konto WHERE saved_id=$id"; //selecting all from DB "Konto" where saved_id is the same as in the array $id
}
else
{
echo "NO saved_id!";
}
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
{
$my['Swordmen'] = $row['swordmen'];
$my['Macemen'] = $row['macemen'];
$my['Pikemen'] = $row['pikemen'];
}
if(isset($_POST['Swordmen']))
{
// the Swordmen Buy button was clicked
$unit = "swordmen";
$qty = $_POST['qty_swordmen'];
}
if(isset($_POST['Macemen']))
{
// the Macemen Buy button was clicked
$unit = "macemen";
$qty = $_POST['qty_macemen'];
}
if(isset($_POST['Pikeman']))
{
// the Pikeman Buy button was clicked - so you need to use qty_Pikemen
$unit = "pikeman";
$qty = $_POST['qty_pikemen'];
}
if(isset($unit) && is_numeric($qty) && $qty > 0) { // if isset($unit) then one of the three buttons was clicked
$sql="UPDATE konto SET $unit=$unit + $qty WHERE saved_id=$id";//Sätt upp SQL fråga.
$result = mysql_query($sql) or die(mysql_error());//Välj all info i tabell.
}
?>
<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<title>Infantrie</title>
</head>
<body bgcolor="#A4A8B0">
<style type="text/css"> <!--selecting the style type-->
<!--
a:link {text-decoration: none; color: black}
a:visited {text-decoration: none; color: black}
a:active {text-decoration: none; color: black}
a:visited {text-decoration: none; color: black}
.textbox { background-color: #DEB887; }
.submit { background-color: #DEB887; }
-->
</style> <!--ending the style type-->
<p>
Är du villig att köpa soldater? Tror du att du är man nog att göra det?
</p>
<table border="1">
<tr>
<th>Units</th>
<th>AtkArm</th>
<th>Buyfor</th>
<th>Sellfor</th>
<th>You Own</th>
<th>Buy</th>
</tr>
<?php while ($row1 = mysql_fetch_assoc($result1)): ?>
<tr>
<th><?php echo $row1['Units'] ;?></th>
<th><?php echo $row1['AtkHp'] ;?></th>
<th><?php echo $row1['Buyfor'] ;?></th>
<th><?php echo $row1['Sellfor'] ;?></th>
<th><?php echo $my[$row1['Units']]; ?></th>
<th>
<font color="black" valign= "top"><input style='width:45;height:20' type="text" name="<?php echo $my[$row1['Units']]; ?>" size="250" class="textbox" value=""></font>
<input style='width:45;height:30;font-weight:bold' name="<?php echo $my[$row1['Units']]; ?>" type="submit" class="submit" value="Buy!">
</th>
</tr>
<?php endwhile; ?>
</table>
</html>
my datatable "konto" will be shown in the attatchments...
- Attachments
-
- This is my entire Data Table called "konto"
- Datatable konto.jpg (45.59 KiB) Viewed 36 times
Last edited by Goofan on Thu Nov 19, 2009 10:32 am, edited 2 times in total.
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: Getting buttons and textboxes within loop
If those are real email addresses, names and (in one case) password, you should seriously consider deleting that attachment and uploading it again with personal details blanked out!!
will have a look through your code again in a minute
will have a look through your code again in a minute
Re: Getting buttons and textboxes within loop
well this is just a prototype so no worries 
altho i got food now so back in 15 min =)
altho i got food now so back in 15 min =)
Re: Getting buttons and textboxes within loop
this is my "output and as u can see i got error on line 95...
- Attachments
-
- Design showing.jpg (72.17 KiB) Viewed 51 times
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: Getting buttons and textboxes within loop
The only explanation I can see is that this line:
is returning no results, which means your sql query is wrong or the table is empty?
try adding this just after the $result = mysql_query() line:
run the script again and it should tell you how many rows its returned. see what you get for that, if its 0 then that explains why $my doesn't exist!
Code: Select all
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.try adding this just after the $result = mysql_query() line:
Code: Select all
echo "Results: ".mysql_num_rows($result);Re: Getting buttons and textboxes within loop
i guess this is what u ment in the put it after mysql....? :
Code: Select all
while($row = mysql_fetch_array( $result )) //hämtar info från tabell.
echo "Results: ".mysql_num_rows($result);
- Attachments
-
- as u see nothing in the "tableboxes"
- this is what i get.jpg (14.88 KiB) Viewed 46 times
- iankent
- Forum Contributor
- Posts: 333
- Joined: Mon Nov 16, 2009 4:23 pm
- Location: Wales, United Kingdom
Re: Getting buttons and textboxes within loop
Not quite
after mysql_query not mysql_fetch_array. after line 29 
although, that should have worked I suppose, it would have just output the same thing three times.
try running the query using phpmyadmin or something to see if you get any results. thats the only obvious reason $my wouldn't have been set
although, that should have worked I suppose, it would have just output the same thing three times.
try running the query using phpmyadmin or something to see if you get any results. thats the only obvious reason $my wouldn't have been set
Re: Getting buttons and textboxes within loop
"just saw it aint becouse i use $my 4 times in 2 diffrent querrys...? look tha the first "without get" querry and then the second "with get"
Re: Getting buttons and textboxes within loop
well i "see" that when i press the button it dosnt uppdate. i guess it aint collecting "ure code" as it aint uppdating maybe u should make an "look a like page to see my result ureself...
"never used phpmyadmin"
never ever got the chance to learn about it... dont know what you do with it more or less
"never used phpmyadmin"
never ever got the chance to learn about it... dont know what you do with it more or less
Re: Getting buttons and textboxes within loop
i get that u can see the stuffs within ure database... and if i look at it that way the "konto" datatable looks fine
Re: Getting buttons and textboxes within loop
i got the result 0 when i used the code u gave me "in right place" i bet thats not good?