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 8778525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:33:45+00:00 2026-06-13T19:33:45+00:00

I’m trying to determine the right syntax from what I’m trying to do with

  • 0

I’m trying to determine the right syntax from what I’m trying to do with MySQL. I’m basically saying that if a value in a certain column of a row of a table is equal to some session variables, I want to echo out info.

I have a table with subject, description and user. User is set by taking the current user’s first name and last name and inserting it into the table under user. This is done by the following code:

$sql="INSERT INTO tbl_name (subject, description, user)
VALUES
('$_POST[subject]','$_POST[description]','$_SESSION[firstname] $_SESSION[lastname]')";

Then once I’m calling this data back out, I want to basically allow the user to delete content that they submitted themselves. The first step for me is to be able to display it in the table. I believe this is just syntax error, but I’ve confused myself now with how things are set up:

$sql = "SELECT * FROM tbl_name ORDER BY subject, description 
  LIMIT {$startpoint},{$limit}";
$result = $mysqli->query($sql);
$num_rows = mysqli_num_rows($result);

if($num_rows>0){
$field_num = $mysqli->field_count;
echo "<h1>HERE ARE SOME EXAMPLES:</h1>";
echo "<table border='0'><tr>";

for($i=0; $i<$fields_num; $i++)
    {
        $field = mysql_fetch_field($result);
        echo "<td>{$field->subject}</td>";
        echo "<td>{$field->description}</td>";
        echo "<td>{$field->user}</td>";
        if('$field->user' == '$_SESSION[firstname] $_SESSION[lastname]'){
          echo '<td>You can delete this</td>';
        }
    }

I figured the $field->user would equal $_SESSION[firstname] $_SESSION[lastname] because that’s how it was initially submitted to the table (without the ‘.’ for concatenation).

Any help would be appreciated. Thanks!

EDIT

Here’s the result of my table output code. The results are actually being display with $cell instead of from within the for loop I believe. I’ve added the if statement in after the but it doesn’t seem to recognize echo "<td>".$field->user."</td>"; which makes me think that that is where the problem lies. What I would like to do is be able to add the if statement in a immediately after `echo {$field->user}”; to keep the code clean. I think I’ve confused myself thoroughly:

if($num_rows>0){
$field_num = $mysqli->field_count;
echo "<h1>HERE ARE SOME JOBS:</h1>";
echo "<table border='0'><tr>";

for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td>{$field->subject}</td>";
    echo "<td>{$field->description}</td>";
    echo "<td>{$field->user}</td>";

    if($field->user == $_SESSION[firstname]." ".$_SESSION[lastname]){
    echo '<td>You can delete this</td>';
    }
    else{
    echo "<td>".$field->user."</td>";
    echo "<td>".$_SESSION[firstname]." ".$_SESSION[lastname]."</td>";
    }
}

echo "</tr>\n";
while($row = mysqli_fetch_row($result))
{
    echo"<tr>";

    foreach($row as $cell)
        echo "<td>$cell</td>";
        echo "</tr>\n";
}
mysqli_free_result($result);
}
else{
echo 'There are no jobs!';
}
  • 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-13T19:33:46+00:00Added an answer on June 13, 2026 at 7:33 pm

    I re-wrote the code in a way that was a little bit easier for me to understand (though maybe not the shortest way to do it):

    while($row = mysqli_fetch_array($result))
    {
        echo"<tr>";
        echo"<td>".$row['subject']."</td>";
        echo"<td>".$row['description']."</td>";
        echo"<td>".$row['user']."</td>";
        if($row['user'] == $_SESSION['firstname']." ".$_SESSION['lastname']){
        echo"<td>You can delete this</td>";
        }
        else{
        echo"<td>Code didn't work</td>";
        }
        echo "</tr>\n";
    }
    

    It ended up working this way. If there’s way to do this shorter then feel free to post it here otherwise thanks for the help!

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.