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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:09:21+00:00 2026-06-02T18:09:21+00:00

So here is what im trying to accomplish: I have worked with SQL plenty

  • 0

So here is what im trying to accomplish: I have worked with SQL plenty of times in the past, but it was always with coldfusion, never with PHP. I have looked over the syntax for making sql queries and have come up with this much (i do believe that using prepare helps protect against sql-injection). My overall goal is to have a page set up to where it pulls all the rows from the jewelry table that has the cat_id corresponding with the categories table. Im just not sure if im starting this off correctly or not. The jewelry table has 4 fields (id, cat id, name, and image)

<?php

 $categorys = $wpdb->get_results ( $wpdb->prepare("SELECT id FROM $wpdb->categories
        WHERE name = '(the_slug())'") );

    $jewelrys = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->jewelry
        WHERE post_status = 'publish'
        AND cat_id = $categorys->id ") );

    foreach ($jewelrys as $jewelry) {
    echo '<div id="jBox"><a href="/wp-includes/images/jewelryImages/' . $jewelry->image . '"><img src="/wp-includes/images/jewelryImages/' . $jewelry->image . '" /><br />' . $jewelry->name . '</div>';
    }
?>

Also i am looking to adding pagination displaying only 9 per page. Any tips or guidance is greatly appreciated =)

Update:
I just tested the category with a simple echo statement to see if it pulled anything, and it didn’t, is this coded wrong?

  • 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-02T18:09:23+00:00Added an answer on June 2, 2026 at 6:09 pm

    To avoid SQL injection, use prepared statements – that way you can pass your variable terms to MySQL as parameters (which it knows not to evaluate for SQL) rather than making them part of your SQL command.

    See How can I prevent SQL injection in PHP?

    To implement pagination, you want to look into MySQL’s LIMIT clause – e.g.

    SELECT ... LIMIT  0,9;  -- get 9 records starting from record 0
    SELECT ... LIMIT  9,9;  -- get 9 records starting from record 9
    SELECT ... LIMIT 18,9;  -- get 9 records starting from record 18
    -- etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I'm trying to accomplish. I have an object coming back from
Hi here's what I'm trying to accomplish. I have a div with ID=columns, in
Here is what I am trying to accomplish. I have a form that uses
I am using SQL Server 2008r2. Here is what I am trying to accomplish:
I have an example here that replicates what I am trying to accomplish. As
Here's the basic idea of what I'm trying to accomplish, I have a list...
Here is what I am trying to accomplish by using NServiceBus. I have a
Ok here's what I'm trying to accomplish. Say I have 100 items. I want
So here is what I am trying to accomplish. First I will have about
Here's what I am trying to accomplish - I have about a million files

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.