Hi i need help coding...

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

User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Hi i need help coding...

Post by Goofan »

i got this datatable where i want to pick stuffs from diffrent rows and to put them into strings

with everything ive tried sofar it dont work however ill post my recent code:

here im trying to get the diffrent rows within the datatable. there are currently 3 rows and in those rows i got 6 cells ( minus one being the id at start).
its the first opening of a datatable that i cant get to work maybe someone can see where the problem is?

- and the "error" that i got is that this comes up after the 4 first "cells"($Units1=$row1['Units']."' WHERE saved=1";$AtkArm1=$row1['AtkArm']."' WHERE saved=1";$Buyfor1=$row1['Buyfor']."' WHERE saved=1";$Sellfor1=$row1['Sellfor']."' WHERE saved=1";) i got this after that the content of the datatable is shown...' WHERE saved=1

the rest of them aint even showing only got this "error" message:

Notice: Undefined variable: Units2 in C:\Program Files\wamp\www\www\Projektarbete\sidor\Infanteries.php on line 117

but at line 117 i got this code

Code: Select all

 
<?php echo $Units2; ?>
 
Dont even know if u can do this "open 2 datatables at the same time...

Code: Select all

 
//first datatable (database)
<?php
include "../login/database.php";        //page to where the database setting is
$sql1="SELECT * FROM units";        //selecting all from DB "units" where saved_id is the same as in the array $id
$result1 = mysql_query($sql1) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
 
                 
while($row1 = mysql_fetch_array( $result1 )) //hämtar info från tabell.
{
    $Units1=$row1['Units']."' WHERE saved=1";
    $AtkArm1=$row1['AtkArm']."' WHERE saved=1";
    $Buyfor1=$row1['Buyfor']."' WHERE saved=1";
    $Sellfor1=$row1['Sellfor']."' WHERE saved=1";
    
}
while($row1 = mysql_fetch_array( $result1 )) //hämtar info från tabell.
{
    $Units2=$row1['Units']."' WHERE saved=2";
    $AtkArm2=$row1['AtkArm']."' WHERE saved=2";
    $Buyfor2=$row1['Buyfor']."' WHERE saved=2";
    $Sellfor2=$row1['Sellfor']."' WHERE saved=2";
}
while($row1 = mysql_fetch_array( $result1 )) //hämtar info från tabell.
{
    $Units3=$row1['Units']."' WHERE saved=3";
    $AtkArm3=$row1['AtkArm']."' WHERE saved=3";
    $Buyfor3=$row1['Buyfor']."' WHERE saved=3";
    $Sellfor3=$row1['Sellfor']."' WHERE saved=3";
}
?>
 
 
 
//new datatable (database)
<?php
 
 
  $id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;
    if($id !== false) {
    $sql="SELECT * FROM inventory 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.
{
    $namn=$row['namn'];
}
?>
 
thanks in advance for any help i get
Last edited by Goofan on Fri Nov 06, 2009 2:53 pm, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hi i need help coding...

Post by RobertGonzalez »

Can you clarify what you are trying to do? It looks like it should be a lot simpler than what you have now.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

well im trying to make so that i can Get from two diffrent dataTables one where i got some information and another table where i got diffrent information. and yes i need to keep them in 2 diffrent...

I first got a script so that the "user" who are loging in will get a saved_id unique to that person and that saved_id will follow him on every page now this ive managed to make.
but on the page im on now im trying to make so that i can both keep the old scripting ,and to Get from the new dataTable, so that i can get the saved_id as he does diffrent stuffes on the page. In the code i want to be able to collect data from a diffrent dataTable within the same database... the other dataTable will have stuffs that will be at a set location at all time thereby saying saved=1 that way im telling the script that the row i need to collect in the dataTable is 1. then i got 3 diffrent rows with diffrent information within them so i need to collect them too. But all need to be collected so that i can put them within a " html table". i need to collect every unique cell within the dataTable

U understand what im trying to explain?

best of luck understanding =)

-Thomas
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hi i need help coding...

Post by RobertGonzalez »

Wouldn't it be easier to just join your tables in a single query to get all the data you need at once?
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

what do u mean...? ill show u a piece of the html coding of where i need it to be set up at.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

Code: Select all

 
        <td>
        <font color="black"><b><?php echo $Units1; ?></b></font>
        </td>
        <td>
        <font color="black"><?php echo $AtkArm1; ?></font>
        </td>
        <td>
        <font color="black"><?php echo $Buyfor1; ?></font>
        </td>
        <td>
        <font color="black"><?php echo $Sellfor1; ?></font>
        </td>
        <td>
        <font color="black"><b>1</b></font>
        </td>
        <td>
        <font color="black" valign= "top"><input style='width:45;height:20' type="text" name="input ITD1" size="250" class="textbox" value=""></font>
        <input style='width:45;height:30;font-weight:bold' name="submit" type="submit" class="submit" value="Buy!">
        
        </td>
 
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

well by saying it like this

if u read it without trying to see what it does u see what im tryning to do'
//Get row where saved is 2 then collect that and put it in @$units2
$Units2=$row1['Units']."' WHERE saved=2";
now the only problem is i got 3 diffrent information fields within the dataTable so i need to get saved 1,2and 3 and put them in diffrent "$Units2"
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hi i need help coding...

Post by RobertGonzalez »

So are you trying to get all rows in `units` where `saved` is in the group 1,2,3?
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

ok right now im experementing with this code

Code: Select all

 
<?php
include "../login/database.php";        //page to where the database setting is
$sql1="SELECT * FROM units";        //selecting all from DB "Konto" where saved_id is the same as in the array $id
$result1 = mysql_query($sql1) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
 
    echo "<table border='1'>";
                 
            while(@$row = mysql_fetch_array( @$result )) //hämtar info från tabell.
            {
                    echo "<tr><td>";
                echo $row[units]." </td><td>".$row[AtkArm]."</td>"$row[Buyfor]." </td><td>".$row[Sellfor]."</td>"; //skriver ut innehållet radvis (inom kaninöron = html kod)
                    echo "</tr>";
            }
                echo "</table>";
?>
 
i found it easier =) as my before maade alot of roubles only problem here is that it aint writing anything at all anything i forgot? or something ive missed? "gotten blind at searching within code all day...
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

complete text "all of all looks rght now like this (experement)
the problem is that it aint writing anything out at all and i think it should if i "read" the code right...?

Code: Select all

 
<?php
include "../login/database.php";        //page to where the database setting is
$sql1="SELECT * FROM units";        //selecting all from DB "Konto" where saved_id is the same as in the array $id
$result1 = mysql_query($sql1) or die(mysql_error());//Välj all info i tall. //hämtar all info från tabell
 
    echo "<table border='1'>";
                 
            while(@$row = mysql_fetch_array( @$result )) //hämtar info från tabell.
            {
                    echo "<tr><td>";
                echo $row[units]." </td><td>".$row[AtkArm]."</td>".$row[Buyfor]." </td><td>".$row[Sellfor]."</td>"; //skriver ut innehållet radvis (inom kaninöron = html kod)
                    echo "</tr>";
            }
                echo "</table>";
?>
 
<?php
 
 
  $id =(isset($_GET['saved_id'])) ? (int)$_GET['saved_id'] : false;
    if($id !== false) {
    $sql="SELECT * FROM inventory 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.
{
    $namn=$row['namn'];
}
?>
 
 
 
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

im tryring to get these out (look at file)
so that they are in a table format like they are in there but so that they are shown to the public and not just in my database
Attachments
this is my database (dataTable)
this is my database (dataTable)
getting these our in table format.jpg (12.28 KiB) Viewed 1267 times
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hi i need help coding...

Post by RobertGonzalez »

Try this:

Code: Select all

<?php
// Get the database connector stuff
include "../login/database.php";
 
// Build our query
$sql = 'SELECT * FROM `units`';
 
// Get the result if there is one
// DO NOT die() IN PRODUCTION!!!
if (!$result = mysql_query($sql)) {
  die('The query<br /><strong>' . $sql . '</strong><br />failed:<br />' . mysql_error());
}
?>
 
<table border="1">
  <tr>
    <th>id</th>
    <th>Units</th>
    <th>AtkArm</th>
    <th>Buyfor</th>
    <th>Sellfor</th>
  </tr>
<?php while ($row = mysql_fetch_assoc($result)): ?>
  <tr>
    <th><?php echo $row['id'] ?></th>
    <th><?php echo $row['Units'] ?></th>
    <th><?php echo $row['AtkArm'] ?></th>
    <th><?php echo $row['Buyfor'] ?></th>
    <th><?php echo $row['Sellfor'] ?></th>
  </tr>
<?php endwhile; ?>
</table>
And please try not to add a bunch of posts inside the thread in reply to yourself. In the future just edit the one that you have already posted so you don't have a conversation with yourself.
User avatar
Goofan
Forum Contributor
Posts: 305
Joined: Wed Nov 04, 2009 2:11 pm
Location: Sweden

Re: Hi i need help coding...

Post by Goofan »

thank you alot =) and btw its alot more fun to talk to yourself then non atall ;) it were exacly what i wanted so thanks alot
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Hi i need help coding...

Post by RobertGonzalez »

Glad I could help.
rodster
Forum Newbie
Posts: 1
Joined: Fri Nov 06, 2009 8:05 pm

Re: Hi i need help coding...

Post by rodster »

i'm just a beginner in php. plzz help me.

why if i write a code to get the "MANPATH" there are no values return. here's my code

<?
print $GLOBALS["MANPATH"];
?>

and if i type

<?
print "<pre>"; print_r($GLOBALS); print "</pre>";
?>

i cant find my "MANPATH"
Post Reply