SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using left() in mysql

    i have a query:


    PHP Code:
    $query "select left(description, 20)";
    $result mysql_query($query);

    while(
    $row mysql_fetch_array($result)) {
    echo 
    $row["description"];

    this is not outputting anything! can anyone see what i'm dewin wrong?

    the werd is out...
    psy

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you selecting from any particular table?
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    yep

    ok here's my full query:

    PHP Code:
    function getMembers() {
            
            
    $query "select id, username, age, sex, location, left(description, 100), left(keywords, 20), left(music, 20), picture, email, icq, aim, yahoo, url, urlname, sign, page_views from users order by id desc";
            
    $result mysql_query($query);

            while(
    $row mysql_fetch_array($result)) {
                echo 
    "<table border=\"0\" align=\"center\" bgcolor=\"#000000\" cellpadding=\"1\" cellspacing=\"1\" width=\"475\">\n\n<tr>";
                echo 
    "\n<td bgcolor=\"#cccccc\" align=\"left\"><b>username: </b>" $row["username"] . "<br />";
                if(!empty(
    $row["location"])) { echo "\n<b>location: </b>" $row["location"] . "<br />"; }
                if(!empty(
    $row["age"])) { echo "\n<b>age: </b>" $row["age"] . "<br />"; }
                echo 
    "\n<b>sex: </b>" $row["sex"] . "<br />";
                if(!empty(
    $row["sign"])) { echo "\n<b>sign: </b>" $row["sign"] . "<br />"; }
                if(!empty(
    $row["email"])) { echo "\n<b>email: </b><a href=\"mailto:" $row["email"] . "\">" $row["email"] . "</a><br />"; }
                if(!empty(
    $row["aim"])) { echo "\n<b>aim: </b>\n<a href='aim:goim?screenname=" $row["aim"] . "&message=hey,+i+saw+you+on+the+merge...'>" $row["aim"] . "</a>&nbsp;&nbsp;<a href='aim:addbuddy?screenname=" $row["aim"] . "'>+</a><br />"; }
                if(!empty(
    $row["yahoo"])) { echo "\n<b>yahoo: </b><a href='http://edit.yahoo.com/config/send_webmesg?.target=" $row["yahoo"] . "'>" $row["yahoo"] . "</a>&nbsp;&nbsp;<a href='http://edit.yahoo.com/config/set_buddygrp?.src=&.cmd=a&.bg=Friends&.bdl=" $row["yahoo"] . "'>+</a><br />"; }
                if(!empty(
    $row["url"])) { echo "\n<a href=\"" $row["url"] . "\">" $row["urlname"] . "</a><br />"; }
                echo 
    "\n<b>views: </b>" $row["page_views"] . "</td>";
                echo 
    "\n<td bgcolor=\"#ffffff\" align=\"left\" valign=\"top\" width=\"250\">";
                if(!empty(
    $row["description"])) { echo "<b>description: </b>" $row["description"] . "<br />"; }
                if(!empty(
    $row["keywords"])) { echo "\n<b>keywords: </b>" $row["keywords"] . "<br />"; }
                if(!empty(
    $row["music"])) { echo "\n<b>music: </b>" $row["music"] . "<br />"; }
                echo 
    "</td>\n</tr>\n\n</table><br />\n\n";
            }


  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well whenever I use a function in my sql I alias the result.

    try: left(description, 20) as desc20
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    <sigh>...

    i really thought that was gonna werk. anymore suggestions possibly?

  6. #6
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you obviously tried aliasing...however, did you also then use $row["aliasname"] later on to display it, i.e did you remember not to just change your sql, but also the display code afterwards ?

    give this a whirl and see if it works for you:

    PHP Code:
    function getMembers() {
            
            
    $query "select id, username, age, sex, location, left(description, 100) as desc100, left(keywords, 20) as keys20, left(music, 20) as music20, picture, email, icq, aim, yahoo, url, urlname, sign, page_views from users order by id desc"// added aliases
            
    $result mysql_query($query);

            while(
    $row mysql_fetch_array($result)) {
                echo 
    "<table border=\"0\" align=\"center\" bgcolor=\"#000000\" cellpadding=\"1\" cellspacing=\"1\" width=\"475\">\n\n<tr>";
                echo 
    "\n<td bgcolor=\"#cccccc\" align=\"left\"><b>username: </b>" $row["username"] . "<br />";
                if(!empty(
    $row["location"])) { echo "\n<b>location: </b>" $row["location"] . "<br />"; }
                if(!empty(
    $row["age"])) { echo "\n<b>age: </b>" $row["age"] . "<br />"; }
                echo 
    "\n<b>sex: </b>" $row["sex"] . "<br />";
                if(!empty(
    $row["sign"])) { echo "\n<b>sign: </b>" $row["sign"] . "<br />"; }
                if(!empty(
    $row["email"])) { echo "\n<b>email: </b><a href=\"mailto:" $row["email"] . "\">" $row["email"] . "</a><br />"; }
                if(!empty(
    $row["aim"])) { echo "\n<b>aim: </b>\n<a href='aim:goim?screenname=" $row["aim"] . "&message=hey,+i+saw+you+on+the+merge...'>" $row["aim"] . "</a>&nbsp;&nbsp;<a href='aim:addbuddy?screenname=" $row["aim"] . "'>+</a><br />"; }
                if(!empty(
    $row["yahoo"])) { echo "\n<b>yahoo: </b><a href='http://edit.yahoo.com/config/send_webmesg?.target=" $row["yahoo"] . "'>" $row["yahoo"] . "</a>&nbsp;&nbsp;<a href='http://edit.yahoo.com/config/set_buddygrp?.src=&.cmd=a&.bg=Friends&.bdl=" $row["yahoo"] . "'>+</a><br />"; }
                if(!empty(
    $row["url"])) { echo "\n<a href=\"" $row["url"] . "\">" $row["urlname"] . "</a><br />"; }
                echo 
    "\n<b>views: </b>" $row["page_views"] . "</td>";
                echo 
    "\n<td bgcolor=\"#ffffff\" align=\"left\" valign=\"top\" width=\"250\">";
                if(!empty(
    $row["desc100"])) { echo "<b>description: </b>" $row["desc100"] . "<br />"// changed to desc100 }
                
    if(!empty($row["keys20"])) { echo "\n<b>keywords: </b>" $row["keys20"] . "<br />"// changed to keys20 }
                
    if(!empty($row["music20"])) { echo "\n<b>music: </b>" $row["music20"] . "<br />"// changed to music20 }
                
    echo "</td>\n</tr>\n\n</table><br />\n\n";
            }

    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •