Computer Forums

Search Tech-Forums.net

Member Login

Remember Me? Sign Up! | Forgot Password
 
 
Computer Forums > Programmers Lounge > Programming Discussions » Need a bit of help with PHP/MySQL (getting the value of a cell)
Reply
Old 12-15-2006, 03:17 PM   #1 (permalink)
 
Newb Techie
Join Date: Dec 2006
Posts: 1
FuzzyLogik
Default Need a bit of help with PHP/MySQL (getting the value of a cell)

Perhaps my problem is I cannot echo the value, as it returns a resource ID.

Here is my code:

Code:
if ($word != "") {
        if ($word == "encyclopedia") {
        echo("

Welcome to the encyclopedia!  Here you will find the meanings of key phrases, such as JavaScript, CSS, and XML.  Remember, you can always access words in the enyclopedia by appending it to the url, e.g. \"http://phazm.net/AJAX\". This will bring up the description of that word.  Enjoy!"); } else {
        $spaces = array("%20", " ", "_", "+", "-", ".");
        $word = str_replace($spaces," ",$word);
        require_once($includes . "connect.php");
        $query = "SELECT * FROM resource WHERE title = '" . $word . "'";
        $result = mysql_query($query);
        $number = mysql_numrows($result);
        $row = mysql_fetch_row($result); 
        $wordid = $row[word_id];
        echo($row . "- Row
WordID is " . $wordid);
        if($number != 0) {
        $query = "SELECT * FROM redirect WHERE word_id = '" . $wordid . "'";
        $result = mysql_query($query);
        $number = mysql_numrows($result);
            if($number <= 1) {
            echo($result);
            } else {
            echo("There are " . $number . " entries for " . $word . ".");
            }
        } else {
        $word = str_replace($spaces," ",$word);
        echo("<h2>" . $word . "</h2>

We have no documentation for " . $word . ".  Please check back later.</p>");
        }
        }
        }
    ?>

Most of that you don't need, but to put at ease those who say "SHOW THE FULL CODE!" - there ya go

Basically, I want to return the ID of the first call.

Search for: Search Engine Optimization

"Search Engine Optimization" is in "title" column of "resource" table, and it's ID (auto_increment) is 8.

How do I get 8?

If I am confusing you, I will rephrase, just ask

Thanks
FuzzyLogik is offline   Reply With Quote
Old 12-17-2006, 09:03 PM   #2 (permalink)
office politics's Avatar
 
It's all just 1s and 0s
Join Date: Jan 2004
Location: in the lab
Posts: 4,181
office politics will become famous soon enough
Default

use mysql_fetch_assoc() to retrieve row results
http://www.php.net/manual/en/functio...etch-assoc.php

PHP Code:
<?php

$conn 
mysql_connect("localhost""mysql_user""mysql_password");

if (!
$conn) {
   echo 
"Unable to connect to DB: " mysql_error();
   exit;
}
  
if (!
mysql_select_db("mydbname")) {
   echo 
"Unable to select mydbname: " mysql_error();
   exit;
}

$sql "SELECT id as userid, fullname, userstatus 
       FROM  sometable
       WHERE  userstatus = 1"
;

$result mysql_query($sql);

if (!
$result) {
   echo 
"Could not successfully run query ($sql) from DB: " mysql_error();
   exit;
}

if (
mysql_num_rows($result) == 0) {
   echo 
"No rows found, nothing to print so am exiting";
   exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//      then create $userid, $fullname, and $userstatus
while ($row mysql_fetch_assoc($result)) {
   echo 
$row["userid"];
   echo 
$row["fullname"];
   echo 
$row["userstatus"];
}

mysql_free_result($result);

?>

office politics is offline   Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On