1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

trying to echo last value in row's array

Discussion in 'MySQL' started by mikemason, Oct 3, 2009.

  1. #1
    Hi, I have this code:
    while($row = mysql_fetch_object($result)) {
                echo "<tr>";
    			echo "<td>" . $row->EmailAddress . "</td>";
    			echo "<td>" . $row->FirstName . " " . $row->LastName . "</td>";
    			echo "<td>" . date('m-d-Y H:m', $row->TimeJoined) . "</td>";
    			$old = $row->TimeJoined;
    			$daysOnList = time()  -  $old;
    			$dd = floor($daysOnList/86400);
    			echo "<td>" . $dd . "</td>";
    			echo "<td>" . $row->ReferralSource . "</td>";
    			echo "<td>" . $row->SentMsgs . "</td>";
    Code (markup):
    and on the last line
    echo "<td>" . $row->SentMsgs . "</td>";
    Code (markup):
    the out put is: 4,5,6,7,8,9,10,11,12 (etc. long ever changing string)

    And I want to only get the last value (in this case it's 12)
    I used:
    echo "<td>" . $row->SentMsgs[$i]; . "</td>";
    Code (markup):
    and the output was only the first value (4), then read I should use the end trigger like:
    echo "<td>" . end($row->SentMsgs) . "</td>";
    Code (markup):
    but it did not work.

    any ideas how I can do this?

    Thanks in advance, Mike
     
    mikemason, Oct 3, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you only need the last result change the query to

    ORDER BY sent_msgs DESC LIMIT 1;
     
    jestep, Oct 3, 2009 IP
    mikemason likes this.
  3. mikemason

    mikemason Peon

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thats a great tip, but where do I put that in?

    Thanks, Mike
     
    mikemason, Oct 3, 2009 IP
  4. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #4
    At the end of query
     
    mwasif, Oct 3, 2009 IP
  5. mikemason

    mikemason Peon

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    well I've been trying but I keep getting errors,
    <?php
    	
    	$username = "xxxxxx";
            $password = "xxxxxx";
            $hostname = "localhost";
            $database = "xxxxxx";
    
            $conn = mysql_connect($hostname, $username, $password)
                or die("Connecting to MySQL failed");
    
            mysql_select_db($database, $conn)
                or die("Selecting MySQL database failed");
    
            $sSQL 	=  "SELECT * FROM InfResp_subscribers WHERE responderid='".$_GET['responderID']."'";
            $resSQL =  "SELECT * FROM InfResp_responders";
    		$result 	= mysql_query($sSQL, $conn);
    		$resultResp = mysql_query($resSQL, $conn);
    
    		while($row = mysql_fetch_object($result)) {
                echo "<tr>";
    			echo "<td>" . $row->EmailAddress . "</td>";
    			echo "<td>" . $row->FirstName . " " . $row->LastName . "</td>";
    			echo "<td>" . date('m-d-Y H:m', $row->TimeJoined) . "</td>";
    			$old = $row->TimeJoined;
    			$daysOnList = time()  -  $old;
    			$dd = floor($daysOnList/86400);
    			echo "<td>" . $dd . "</td>";
    			echo "<td>" . $row->ReferralSource . "</td>";
    			echo "<td>" . $row->SentMsgs . "</td>"; 
    			try {
    				$rt = mysql_query("SELECT MsgList FROM InfResp_responders INNER JOIN InfResp_subscribers ON InfResp_responders.ResponderID=InfResp_subscribers.ResponderID WHERE InfResp_subscribers.SubscriberID='". $row->SubscriberID ."' LIMIT 1", $conn);
    				while($tt = mysql_fetch_object($rt)) {
    					echo "<td>" . $tt->MsgList . "</td>";
    				}
    			} catch(Exception $iop) {}
    			echo "</tr>";
            }
    	?>
    Code (markup):
    Thanks for all the help, Mike
     
    mikemason, Oct 3, 2009 IP
  6. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #6
    If SendMsgs contains comma separated values then you can get the last value by replacing
    echo "<td>" . $row->SentMsgs . "</td>"; 
    Code (php):
    with
    echo substr(strrchr($row->SentMsgs, ","), 1);
    Code (php):
     
    mwasif, Oct 5, 2009 IP
    mikemason likes this.
  7. mikemason

    mikemason Peon

    Messages:
    184
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That worked great mwasif, thanks!
    *sent a rep :)
     
    mikemason, Oct 6, 2009 IP
  8. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #8
    Welcome and thanks
     
    mwasif, Oct 8, 2009 IP