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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:48:59+00:00 2026-05-22T01:48:59+00:00

I am having trouble setting up a query, it seems very simple but I

  • 0

I am having trouble setting up a query, it seems very simple but I cannot seem to determine if my database logic is incorrect or whether the query is incorrect.

There is one database with 3 tables, clients, orders and package.

The clients table has 3 fields, ID{primary key auto increment), email (varchar) and organisation (varchar).

The orders table has 10 fields, ID(from above), OderID (PRimary, autoincrement), WorkID (from package table), and othr fields relating to file paths, comments, feedback and date.

The package table has 2 fields, WorkID (primary Key autoincrem), name(varchar)

This is what I want the query to do:

The query must get all the rows from orders table where WorkID= 1 and must get the organisation field from clients based on each order. I am then going to order the rows by date.

Am I meant to be suing a join to get this query to work or is there a flaw in the database logic? Now yes I already know there is an error below as i am not comparing an ID from the two tables, but what I want to happen is for it to first get all the rows from orders where WorkID = 1 then add the clients.organisation field to each row found from WorkId = 1 where ID from clients corresponds to the ID assigned to that row.

Thanks for any help

$query =    "SELECT * 
             FROM orders INNER JOIN clients ON orders.ID = clients.ID
             WHERE WorkID = 1
             ORDER BY Date DESC";

WORKING NOW__________________________————————->>>>>>>>>>>>>>>>>>>>>>>>>>>

Ok guys ive got the query working but for some odd reason the number of rows being echoed in while loop i have set up is always 1 less than num_rows. Anyone have any idea as to why? This is my echo

<?php
include "../includes/connect.php";

$query =    "SELECT * 
             FROM orders INNER JOIN clients ON orders.ID = clients.ID
             WHERE WorkID = 1
             ORDER BY Date DESC";

$result = mysqli_query( $link , $query );


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="google-site-verification" content="qH5HloAtcJbjEVuEx3vDy_Rmj7Zjw8Mtsuuqdrd1c3Y" />
<link href="../styles/dark-main.css" rel="stylesheet" type="text/css" />
<link href="../styles/nivo-slider.css" rel="stylesheet"  type="text/css" media="screen" />
<link href="../styles/jquery.galleryview-3.0.css" rel="stylesheet" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../scripts/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript" src="../scripts/page-scripts.js"></script>
<script type="text/javascript" src="../scripts/jquery.easing.1.3.js"></script>
<script type="text/javascript" src="../scripts/jquery.galleryview-3.0.js"></script>
<script type="text/javascript" src="../scripts/jquery.timers-1.2.js"></script>
<script type="text/javascript" src="../scripts/validator.js"></script>


</head>

<body class="portfolio">

<!--TOPBAR STARTS HERE-->
<?php include"../includes/topbar.php"; ?>
<!--TOPBAR ENDS HERE-->

<!--HEADER STARTS HERE-->
<?php include"../includes/header.php"; ?>
<!--HEADER ENDS HERE-->

<!--SLIDER STARTS HERE-->
<?php include"../includes/slider.php"; ?>
<!--SLIDER ENDS HERE-->

<!--MIANCONTENT STARTS HERE-->

<div class="contentcontainer">

    <div class="contentcontainercenter">



    <div class="portfoliowrapper">
    <h2>Portfolio</h2>
    <div class="box">

    <div id="conversionworks" class="conversionwork">
    <h3>Heading</h3>
    <span class="message"> message </span>

    <div class="blockwrapper">

    <?php
    while( $row = mysqli_fetch_array( $result ) ){                           
  echo '
  <div class="itembox">
    <div class="imagewrapper">
    <a class="thumbnail" href=""><img src='. $row['ThumbPath'].' /><span><img src='. $row['FilePath'].' /></span></a>
    </div>
    <div class="detailsbox">
    Company:<span class="details"> '.$row['Organisation'].' </span><br />
    Theme:<span class="details">  '.$row['Theme'].' </span><br />
    Uses:<span class="details">  '.$row['Tech Used'].' </span>
    </div>
    </div>'      
;}
?> 

Also i have a question i regards to safety of a database. I have file paths stored in the database which get echoed according to each record fetch no user interaction all done via the server on page load, is it insecure to do so?

2nd question i have mutiple queries on the 1 page, what would be the best way to include each query where it is required? (Would putting it in a separate file and calling it before the echo be best?)

  • 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-22T01:48:59+00:00Added an answer on May 22, 2026 at 1:48 am

    You probably need something like that:

    SELECT * 
    FROM orders o
    INNER JOIN clients c ON (c.id = o.id)
    WHERE o.WorkID = 1
    ORDER BY `Date` DESC
    

    Some side notices : you should change your column naming convention to something more descriptive (I’m talking about orders.id which is in your case is a reference to clients.id). Personally, I prefer to use id as a primary key in each table. Some people like to name it as [TABLE_NAME]_id, in your case order_id, client_id. Secondly, don’t use *; list all required fields. Also, I’d recommend to use a newer sql syntax for joining table (use JOIN keyword instead of listing all tables in FROM clause).

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

Sidebar

Related Questions

I'm having trouble setting fixed widths on columns which use colspan . It seems
I am having trouble setting the path to jquery in an mvc app. In
We're having trouble setting window captions using cyrillic or japanese characters. We either see
Hey guys - I am having trouble setting up my Django urls file correctly
I'm having trouble setting up a Graphic object (a solid filled rectangle) to be
I'm having trouble setting HTML <select> font-size on OS X Safari and Chrome. Basically
I am having trouble setting the Selected Item of a Listbox I am populating
I am having trouble setting up pagination on codeigniter when I pass parameters in
I am having trouble setting the minimum size of my window in a C#
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the

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.