Jump to content

Get $results[$i] to stop counting?


Guest robj

Recommended Posts

Guest robj

I'm modifying the siteDocs.inc.php file to only display the first 5 id's. How can I end the count for $results[$i] within siteDocs.inc.php?

Explanation:

If doc_id = 6 end count and display

Hope that helps

-rob

Link to comment
Share on other sites

Guest robj

Found a solution. To exlude docID's above 5, I opened siteDocs.inc.php and:

changed

$results = $db->select("SELECT doc_id, doc_name FROM ".$glob['dbprefix']."CubeCart_docs ORDER BY doc_name ASC");




to


$results = $db->select("SELECT doc_id, doc_name FROM ".$glob['dbprefix']."CubeCart_docs WHERE doc_id < 6 ORDER BY doc_name ASC");

Hope this help someone else.

-rob

Link to comment
Share on other sites

Guest EverythingWeb

That will work without issue, unless you say deleted a site doc, added it as a new one, and it was added in the database with a higher value in the sitedoc id column (auto_increment).

The fix in the results loop line would be to change:

for ($i=0; $i<count($results); $i++){

to:

for ($i=0; $i<5; $i++){

HTH.

Link to comment
Share on other sites

Let me ask this, in response to " auto_increment":

If I deleted doc 3 (of the 6 docs) would the next doc I create have an id of 3 or would it be 7?

It seems to me that either change would create a different problem. Unless there is a way to define which ID is to display on a specific navigation area, the admin will just have be be diplomatic on what to display.

Also, the loop change has been tested and does work (for those anonymous visitors).

Link to comment
Share on other sites

Guest EverythingWeb

It would be ID 7 :lol:

Yes, both could cause issue, you're right. You can always edit the value of the auto_increment in the database record, but it depends how heavy you want to get

Link to comment
Share on other sites

Making changes to the db woudn't be an issue for me, but for someone with less knowledge it might. I suggest plan ahead then create.

Good info. Thanks

-rob

Link to comment
Share on other sites

  • 2 weeks later...

More fun:

Currently within siteDocs.inc.php this is the display results function:

$results = $db->select("SELECT doc_id, doc_name FROM ".$glob['dbprefix']."CubeCart_docs WHERE doc_id < 6 ORDER BY doc_name ASC");

How can I change this to get docs starting at id 2 through 6, eg:

WHERE doc_id > 1 && < 6 (this code doesn't work)

thanks

-rob

Link to comment
Share on other sites

That won't work Will. The "WHERE 1" does nothing. And you can't use multiple conditionals like that....it'll throw an error. The proper way would be:

SELECT doc_id, doc_name FROM ".$glob['dbprefix']."CubeCart_docs WHERE doc_id >= 2 AND doc_id <= 6 ORDER BY doc_name ASC

Here are two pages that are indispensable when trying to construct SQL queries:

MySQL - Functions and Operators

MySQL - SQL Statement Syntax

There are other pages on data types and such that are great too, but those to sections should be read by anybody who really wants to learn how to get the most out of their database. ;)

:)

Link to comment
Share on other sites

Guest EverythingWeb

Sorry Bill.

It was nearly 3 in the morning and had been up and awake for around 18 hours! Wasn't thinking straight. I've duly slapped myself.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...