#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    Hey guys,


    I've been trying to figure this out for the last two days. I'm trying to pull out the entry_description "BLOB" in the table called 'helpdesk', then use substr() to cut it down to 200 characters with a trailing '...'. finnaly take the result of the substr() operation, make it into a hyperlink and put it in a table. I have looked at a previous post that was almost identicle to this, but still can't figure it out. Here is the code I've been working with:

    <html>

    <body bgcolor="#0000FF">
    <?php

    include 'mail.inc'; // Use this for all mail procedures



    $db = mysql_connect("localhost", "web", "web");

    mysql_select_db("helpdesk",$db);

    if ($id == "")
    {$id = '%';}

    if ($extension == "")
    {$extension = '%';}

    if ($name == "")
    {$name = '%' ;}

    // entry description is a hidden form field
    if ($entry_description == "")
    {$entry_description = '%' ;}


    $result = mysql_query("SELECT * FROM helpdesk WHERE id LIKE '$id%' AND name LIKE '$name%' AND entry_description LIKE '$entry_description%'");

    $resultdescription = mysql_query("SELECT CONCAT(LEFT('entry_description',200),'...') as first200 FROM helpdesk");

    $row = mysql_fetch_array($resultdescription);

    //echo $row["first200"];



    if ($myrow = mysql_fetch_array($result)) {

    echo"
    <head>
    <title>Search Results</title>
    </head>
    <body bgcolor='#0000FF'>
    <div align='center'>
    <center>
    <table border='0' width='70%' cellspacing='0' cellpadding='0' bgcolor='#FFFFFF'>
    <tr>
    <td width='100%' bgcolor='#0000FF' valign='middle' align='left'>
    <img src='http://database.techsonic.com/images/helpdesk.jpg' width='87' height='619'
    alt='Help Desk'></td>
    <td width='100%'><img src='http://database.techsonic.com/images/cornertop.jpg' width='873'
    height='20' alt>
    <table border='1' width='100%' bgcolor='#d7deff'><tr><td width='7%'>id</td><td width='18%'>Name</td><td width='75%'>Problem Description</td></tr>";

    do {
    //print ($i%2)? "<tr bgcolor="d7deff">":"<tr bgcolor="c2ccff">";

    //this is where I want to spit the substr() result into the table

    printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>n", $myrow["id"], $myrow["name"], $row["first200"]);
    } while ($myrow = mysql_fetch_array($result));

    } else {

    echo "<p>Sorry, no records were found!</p>";
    print("<p>");

    }


    echo "</p>";
    echo"<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>";
    echo "<p><a href=http://database.techsonic.com/index.html>Go back...</a></p>";
    echo"</table><p>&nbsp;</p><p align='center'>&nbsp;</p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p><img src='http://database.techsonic.com/images/cornerbottom.jpg' width='873'
    height='20' alt></td>
    </tr>
    </table>
    </center></div>";
    ?>
    </body>
    </html>


  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    I can't even get this little snippet of code to work


    <?
    //$date = gmdate( "M d H:i:s");
    //echo "$date";

    $db = mysql_connect("localhost", "web", "web");
    mysql_select_db("helpdesk",$db);
    $result = mysql_query("SELECT * from helpdesk");
    //$first200 = substr($result, 0, 500) . "...";


    echo "$result";

    ?>

    I can't even get it display $result, all it says is "Resource id #2"

    How retarted am I ??
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    29
    Rep Power
    0
    Your just midly retarded... lol j/k.

    It technically is correct, the $result only holds the reference to the result at that point, you need to use something like, mysql_fetch_array, that will then use the reference and get your actual data, so the code to just show what your result is would be:

    <?

    $db = mysql_connect("localhost", "web", "web");
    mysql_select_db("helpdesk",$db);
    $result = mysql_query("SELECT * from helpdesk");

    $ResultArray = mysql_fetch_array($result)

    for($index = 0; $index < count($ResultArray); $index++)
    {
    echo "$ResultArray[$index]<BR>n";
    }

    ?>

    As for the first code, I am not exactly sure, as I didn't go through it line by line, but I will look at it later :-).

    Vlad
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    10
    Rep Power
    0
    hehe,


    thanks for the help man. The first post is whats eating me alive. That would be great if you could look at it, later of course


    -honky
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    29
    Rep Power
    0
    I am not an SQL expert at all, but I think it might work better if you selected it out of the database and then did the manipulations, like:

    // entry description is a hidden form field
    if ($entry_description == "")
    {$entry_description = '%' ;}


    $result = mysql_query("SELECT * FROM helpdesk WHERE id LIKE '$id%' AND name LIKE '$name%' AND entry_description LIKE '$entry_description%'");

    if ($myrow = mysql_fetch_array($result)) {

    $desc = substr($myrow["entry_description"], 0, 200);
    $desc .= "...";


    I have not tested this, so it may not work, but try it :-)

  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    The first thing that jumps out is that you need to remove the single quotes from around entry_description in the resultdescription query. With the quotes you are telling MySQL to use entry_description literally, not the field named entry_description.

    You don't say what the exact problem is so it's hard to find an error without knowing what's wrong.
  12. #7
  13. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,648
    Rep Power
    4493
    Yeah...what rod said first of all. Also, you can do the query with one command. I'd stay away from doing select *, just select the columns you need.

    $result = mysql_query("SELECT id, name, CONCAT(LEFT(entry_description,200),'...') as first200 FROM helpdesk WHERE id LIKE '$id%' AND name LIKE '$name%' AND entry_description LIKE '$entry_description%'");
    $row = mysql_fetch_array($result);
    echo $row[id];
    echo $row[name];
    echo $row[firs200];

    Also, for Vlad The Impaler, yes you can just select the whole blob out of the database and then do the substr and concat in PHP, but it's also very possible to just do it in mysql. most people don't realize this. Now...which one is faster, I can't say. That would be a good test for someone to run..

    ---John Holmes...

IMN logo majestic logo threadwatch logo seochat tools logo