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

  • Home
  • SEARCH
  • 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 759973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:39:40+00:00 2026-05-14T15:39:40+00:00

I am a college student taking a course in php and mysql progamming and

  • 0

I am a college student taking a course in php and mysql progamming and my first question is about the “$variable” variables in the following code:

<?php ob_start(); ?>

<?php

session_start();

if ($_SESSION['auth'] != "true")
{ header("Location: login.php");
  exit;
}

$uid = $_SESSION['user'];

$connection = mysql_connect("localhost", "username", "password");

mysql_select_db("username", $connection);

$result = mysql_query ( "SELECT * FROM users where user_id = '$uid'", 
$connection);

$num = mysql_numrows($result);

$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"firstname");
$f2=mysql_result($result,$i,"lastname");
?>

<html><body>
<p>
<td><center><font size = "18" face="Arial"><?php echo "Name: $f1 "; echo $f2; ?> </font></center></td>
</p>
</body></html>

<?php
$i++;
}
?>


<?php

$result1 = mysql_query ( "SELECT * FROM phone where user_id = '$uid'", $connection);

$num1 = mysql_numrows($result1);

$j=0;
while ($j < $num1) {
$f3=mysql_result($result1,$j,"type");
$f4=mysql_result($result1,$j,"number");
?>

<html><body>
<p>
<br>
<td><center><font size = "12" face="Arial"><?php echo "$f5: "; echo "($f3) "; echo "$f4 <br />"; ?> </font></center></td>
</p>
</body></html>

<?php
$j++;
}
?>

<?php

$result2 = mysql_query ( "SELECT * FROM address where user_id = '$uid'", $connection);

$num2 = mysql_numrows($result2);

$h=0;
while ($h < $num2) {
$f6=mysql_result($result2,$h,"type");
$f7=mysql_result($result2,$h,"address");
$f8=mysql_result($result2,$h,"city");
$f9=mysql_result($result2,$h,"state");
$f10=mysql_result($result2,$h,"zip");
?>

<html><body>
<p>
<br>
<td><center><font size = "12" face="Arial"><?php echo "$f10 Address: $f6, $f7, $f8 $f9"; ?></font></center></td>
</p>
</body></html>

<?php
$h++;
}
?>

<?php

include 'navbar.php';

ob_end_flush();

?>

I just don’t really understand the $variables at all. Are they user-generated or are they entities in the database? And how does the code know which $result is which?

My second question is that, if this was someone else in my class’s code and I wanted to modify it to make it my own and substitute my own variables, how would I go about doing that? Do the $variables need to be changed if they are not user-defined and if so, how? I apologize if these are dumb questions, but I am a beginner at this programming language. Thanks in advance for your help.

-Jeff

  • 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-05-14T15:39:40+00:00Added an answer on May 14, 2026 at 3:39 pm

    In PHP you don’t need to define the variables and neither the var type. That’s mean that the variable declaration is implicit in any new assignment.
    The $ symbol it’s used by PHP to understand that it’s a variable.

    An example:

    $result = mysql_query ( "SELECT * FROM users where user_id = '$uid'", $connection);
    

    With this line you do basically 3 things:

    1. Define a new variable called $result
    2. Set the variable type based on the result type of your function a resource in this case
    3. Assign the function’s result to the variable.

    you can learn more about PHP variables and types on php.net, could be interesting for you also read more about === operator

    next time, could you please use the code tag in your post ? 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.