Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:47:20+00:00 2026-06-17T11:47:20+00:00

I’m trying to create a variable which is dependent on some information from the

  • 0

I’m trying to create a variable which is dependent on some information from the database. I’m trying to generate a $path variable which stores a path, depending on what information is recovered from the database.

$linkid = mysql_connect('localhost','user','password');
mysql_select_db("table", $linkid);
$variable = "00001";
$groupID = null;
$temp = mysql_query("SELECT groupID FROM table WHERE memberID='$variable'", $linkid);

while ($row = mysql_fetch_row($temp)){
    global $groupID;
    foreach ($row as $field){
        $groupID = $field;
    }
}

....

$path = "C:\WAMP\www\project\\" . $groupID;
$dir_handle = @opendir($path) or die('Unable to open $path');

The idea behind this is that $variable is set before the PHP is run, however it’s set to 00001 for testing. The ideal situation is that $path should equal C:\WAMP\www\project\00001\. Currently, when I echo back the $path all I get is the original path without the $groupID added to the end.

I also receive the message “mysql_fetch_row() expects parameter 1 to be resource” but I’ve used this method for retrieving information before and it worked just fine, and I set up my table in the same way so I don’t think the issue is there.

I have a feeling I’m missing something obvious, so any help is appreciated. It’s not for an assignment or anything school related (just trying stuff out to learn more) so knock yourselves out with correcting it and explaining why 🙂

In addition, only one memberID will ever be a match to the $variable, so if there’s an alternative way to fetch it I’d appreciate knowing.

Oh, and I know my variable names are shocking but they’re only that on here, on my actual code they’re different so no criticism please :p

EDIT: The SQL query is correct, after following BT634’s advice and when running it on phpMyAdmin I get the groupID I want and expect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:47:21+00:00Added an answer on June 17, 2026 at 11:47 am

    First of all, you’re not specifying what database to connect to in your connection – you’re specifying what table. You might also want to check how many rows your query is returning:

    $temp = mysql_query("SELECT groupID FROM table WHERE memberID='$variable'", $linkid);
    echo mysql_num_rows($temp);
    

    If it’s still complaining about $temp not being a valid resource, change your MySQL connection code to:

    // Establish connection
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con) die('Could not connect: ' . mysql_error());
    mysql_select_db("my_db", $con);
    
    // Make your query
    $result = mysql_query("SELECT groupID FROM table WHERE memberID='$variable'");
    
    // Find out what the value of the query is (i.e. what object/resource it is)
    var_dump($result);
    

    Once you know that MySQL is returning valid data, extract the values you want. You don’t have to use globals:

    while ($row = mysql_fetch_row($temp)){
        $groupId = $row[0];
    }
    
    // Use $groupId however you please...
    

    One thing to bear in mind is that mysql_fetch_row will return

    array
    (
       0 => '...'
    )
    

    Whilst mysql_fetch_assoc will return:

    array
    (
       'groupId' => '...'
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.