I need help again, please guys

Discussion in 'PHP' started by SnoozZz, Jul 17, 2008.

  1. #1
    I use this to display my reps sales and commisions. anyone any idea please...
    <?php 
    $sql = "SELECT * FROM data WHERE rep='$name' AND status='success'"; 
    $result = mysql_query($sql); 
    while ($record = mysql_fetch_object($result)) { 
    
    $question = nl2br($record->description);
    $answer = nl2br($record->answer);
    ?>
        <tr class="tdhoverActive" align="left" style="cursor:hand;" onmouseover="this.className='tdhover2Active';" onmouseout="this.className='tdhoverActive';">
          <td width="23%" valign="top">
            <font class="small">
          <div align="center"><?php echo "$record->date";?></a></div></td>
        
    <td width="27%" valign="top">
      <div align="center"><?php echo "$record->client"; ?></a></div></td>
        
        
        <td width="25%" valign="top"><div align="center"><?php echo "$record->amount"; ?>&nbsp;</div></td>
        <td width="25%" valign="top"><div align="center"><?php echo "$record->com"; ?>&nbsp;</div></td>
        <?php
    }
    ?>
      </table>
    </div>
    <div align="left">
      <p>
    
    PHP:
    Is there a possible way to add a line at the bottom to add up all the sale amounts and commissions?
     
    SnoozZz, Jul 17, 2008 IP
  2. MartinGr

    MartinGr Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just add <td width="25%" valign="top"><div align="center"><?php echo $record->com+$record->amount; ?>&nbsp;</div></td>
     
    MartinGr, Jul 17, 2008 IP
  3. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    that would calculate $amount + $com

    I need to calculate all the $com displayed

    and seperately all the $amount
     
    SnoozZz, Jul 17, 2008 IP
  4. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #4
    and you didn't show us all the varibles that are $com and all the var's that are $amount. So, do the same thing as they did, but with all the $com amounts and then seperatly with all the $amount var's. Then display them.
     
    exodus, Jul 17, 2008 IP
  5. MartinGr

    MartinGr Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh, sorry. In that case add before $question = nl2br($record->description);

    $totalAmount += $record->amount;
    $totalCommission += $record->com;
    
    PHP:
    And display the values of the variables somewhere outside the loop.
     
    MartinGr, Jul 17, 2008 IP
  6. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yip, that worked, thank you so much..
     
    SnoozZz, Jul 17, 2008 IP
  7. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I'm probably doing this all wrong but seems that it could work.

    my string
    http://localhost/pnt/admin/?q=new2&name=Gladis
    PHP:
    I have list of clients with reps assigned to them. to check if specific rep has clients and add as sale I use this.

    <?php
    $sql = "SELECT * FROM clients WHERE rep='$name'";
    $result = mysql_query($sql);  
    while ($rep = mysql_fetch_object($result)) 
    	{
    
    $checkrep = "$record->rep";
    
    	}
    
    	if($rep == "$checkrep") 
    	{
    ?>
    
    <form action="?q=new3" method="post">
      <table width="347" border="0" align="center">
        <tr>
          <th scope="row">&nbsp;</th>
          <td>
    <?php  
    	  $sql = "SELECT * FROM clients WHERE rep='$name'";
    $result = mysql_query($sql); 
    while ($record = mysql_fetch_object($result)) 
    	{
    ?>
          <input name="rep" type="text" id="rep" value="<?php echo"$record->rep";?>" />
        </tr>
        <tr>
          <th scope="row">client</th>
          <td><select name="client" id="client">
    
    
            <option value="<?php echo "$record->cname";?>"><?php echo "$record->cname";?></option>
    
          </select>    </tr>
        <tr>
          <th scope="row">amount</th>
          <td><input name="amount" type="text" id="amount"></td>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td><input type="submit" name="Submit" value="Submit"></td>
        </tr>
      </table>
    </form>
    <?php
    	}
    ?>
    <b><?php echo "$name has no clients. First add clients to $name 's account"; ?></b>  <a href="../index.php?q=client">here</a>
    
    <?php
    	}
    ?>
    PHP:
    so if this rep is not assigned to any clients... at the moment it's adding it to reps wheter they have clients or not.

    <b><?php echo "$name has no clients. First add clients to $name 's account"; ?></b>  <a href="../index.php?q=client">here</a>
    PHP:
    I probably need else { somewhere.... any ideas?
     
    SnoozZz, Jul 19, 2008 IP
  8. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #8

    Both your SQL queries are the same, are you sure its supposed to be that way?
    What are you actually trying to accomplish here?
    List all the customer names for a specific rep?
     
    Talker, Jul 19, 2008 IP
  9. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I need a list clients for specific rep ie. Gladis yes. but if Gladis has no clients, it must tell me "Gladis has no clients. First add clients to Gladis 's account". without dispalying the form.

    If Gladis has clients, it must display the form and not "Gladis has no clients. First add clients to Gladis 's account".

    like I say, i'm probably dong this all wrong.

    currently it's working but is adding the "Gladis has no clients. First add clients to Gladis 's account". line, whether the rep has clients or not
     
    SnoozZz, Jul 19, 2008 IP
  10. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #10

    Yeah thats more like it.. i usually work on live Databases, but let me see what i can do for you here... ill post back shortly.
    Please tell me what q=new2 is for??


    ,,
     
    Talker, Jul 19, 2008 IP
  11. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    ?q is the handler to include page new2.php in my main page content.

    not sure how to explain it.
     
    SnoozZz, Jul 19, 2008 IP
  12. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #12
    Try this and give me your feedback:

    
    <?php
    $name = $_GET['name'];
    
    $sql = "SELECT * FROM clients WHERE rep='$name'";
    $result = mysql_query($sql);
    if(!$result) { die(mysql_error()); }
    $numrows = mysql_num_rows($result);
    if ($numrows>0)  {
    $i = 0;
    
    ?>
    <form action="?q=new3" method="post">
      <table width="347" border="0" align="center">
    
    <?php
    
    
    while($i<=($numrows -1)) {
    
    ?>
        <tr>
          <th scope="row">&nbsp;</th>
          <td>
          <input name="rep" type="text" id="rep" value="<?php echo"$record->rep";?>" />
        </tr>
        <tr>
          <th scope="row">client</th>
          <td><select name="client" id="client">
    
    
            <option value="<?php echo "$record->cname";?>"><?php echo "$record->cname";?></option>
    
          </select>    </tr>
        <tr>
          <th scope="row">amount</th>
          <td><input name="amount" type="text" id="amount"></td>
        </tr>
        <tr>
          <th scope="row">&nbsp;</th>
          <td><input type="submit" name="Submit" value="Submit"></td>
        </tr>
    
    <?php
    
    }
    ?>
      </table>
    </form>
    <?php
    
    
    }else{
    ?>
    <b><?php echo "$name has no clients. First add clients to $name 's account"; ?></b>  <a href="../index.php?q=client">here</a>
    
    <?php
    }
    
    ?>
    
    
    PHP:
     
    Talker, Jul 19, 2008 IP
  13. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    I stand to be corrected, its not working, its duplicating the form for each client.

    Nope its not working, but don't worry about it too much, I don't really nead the function

    but here is my client table structure if youd like to take another crack at it.

    `id` int(10) NOT NULL auto_increment,
    `cname` varchar(50) default NULL,
    `number` varchar(20) default NULL,
    `email` varchar(100) default NULL,
    `rep` varchar(50) default NULL,
    `status` varchar(10) default NULL,
    PRIMARY KEY (`id`)
     
    SnoozZz, Jul 19, 2008 IP
  14. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #14
    Ill get back to you with the correct code, can you please give me the SQL query to create the table (not just the structure).
     
    Talker, Jul 19, 2008 IP
  15. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    CREATE TABLE `clients` (
      `id` int(10) NOT NULL auto_increment,
      `cname` varchar(50) default NULL,
      `number` varchar(20) default NULL,
      `email` varchar(100) default NULL,
      `rep` varchar(50) default NULL,
      `status` varchar(10) default NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=15 ;
    
    -- 
    -- Dumping data for table `clients`
    -- 
    
    INSERT INTO `clients` (`id`, `cname`, `number`, `email`, `rep`, `status`) VALUES 
    (1, 'Dr Green', '123456789', 'mail@mail.com', 'Gladis', 'processed'),
    (2, 'Mr Brown', '321654987', 'mail@mail.com', 'Gladis', 'processed'),
    (3, 'Mrs White', '963258741', 'blom@mail.com', 'Gladis', 'processed'),
    
    PHP:
     
    SnoozZz, Jul 19, 2008 IP
  16. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #16
    I have to leave right now. I'll get this done for you on Monday.. not sure if that would help.. please leave me a message on this thread if you want me to work on it on Monday.
     
    Talker, Jul 19, 2008 IP
  17. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    this app. is for personal use. so I'm not too concerned about it, it was simply an idea I had but I don't have enough knowlege of php. If you could do it, it will be much appreciated. Thanx for your help thus far.
     
    SnoozZz, Jul 19, 2008 IP
  18. Talker

    Talker Notable Member

    Messages:
    2,795
    Likes Received:
    108
    Best Answers:
    0
    Trophy Points:
    210
    #18
    I'm honestly so busy with work, i have numerous projects lined up.
    If its something your not too concerned about, i guess i should leave this aside. Sorry, but i really have so much work on me.
     
    Talker, Jul 21, 2008 IP
    SnoozZz likes this.
  19. SnoozZz

    SnoozZz Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    no problem, thanx for your help.
     
    SnoozZz, Jul 21, 2008 IP