Jump to content

Display all MySQL items in database


brosskgm

Recommended Posts

I have some PHP/Java code that was written for me that searches and displays an item(s) costs etc. Similar to a parts store

but with a eCart twist. This was so long ago that I'm no longer able to contact the coder. He no longer in school and they can't

tell you were he went to. I guess he got a good grade for the project and got hired.

 

I only have about 20-25 items in the database. Can someone tell here where in the attached code I can tell it to

display all the contents of the database with out using the search but leaving all the other functions usable?

 

If you need any other files not in the attachment, let me know. There are several more, but these were most of the php

files in the main directory.

 

Thanks in advance.

Bob Ross

18055_.zip

Link to comment
Share on other sites

Sorry. There wasn't much in there and I wasn't sure if it would have been needed.

 

Search.php

 


<?php
require_once "dbConnect.php";
Class Search {
private $ResultArray, $numRows;
public function __construct() {
	if ($_GET['s']) {
		$safeQuery = mysql_real_escape_string($_GET['s']);
		$theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'";
		$res = mysql_query($theQuery);
		$this->numRows = mysql_num_rows($res);
		$i = 0;
		while ($result = mysql_fetch_array($res)) {
			$this->ResultArray[$i] = $result;
			$i++;
		}
	}
	else { $this->numRows = -1; }
}
public function getResult() {
	return $this->ResultArray;
}
public function getNumRows() {
	return $this->numRows;
}
public function __destruct() {
	mysql_close();
}

}
?>


 

It looks like your search class is what does the searching. You would need to post the search.php code.

Link to comment
Share on other sites

You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table -

 

<?php
public function __construct() {
	if(isset($_GET['s']) && $_GET['s'] != '') {
		$safeQuery = mysql_real_escape_string($_GET['s']);
		$theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'";
	} else {
		$theQuery = "SELECT * from parts";
	}
	$res = mysql_query($theQuery);
	$this->numRows = mysql_num_rows($res);
	$i = 0;
	while ($result = mysql_fetch_array($res)) {
		$this->ResultArray[$i] = $result;
		$i++;
	}
}

 

The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name.

Link to comment
Share on other sites

What file would I put this in?

 

Thanks

 

You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table -

 

<?php
public function __construct() {
	if(isset($_GET['s']) && $_GET['s'] != '') {
		$safeQuery = mysql_real_escape_string($_GET['s']);
		$theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'";
	} else {
		$theQuery = "SELECT * from parts";
	}
	$res = mysql_query($theQuery);
	$this->numRows = mysql_num_rows($res);
	$i = 0;
	while ($result = mysql_fetch_array($res)) {
		$this->ResultArray[$i] = $result;
		$i++;
	}
}

 

The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name.

Link to comment
Share on other sites

You would just modify the query logic so that if no search term is provided, you retrieve all rows from the table -

 

<?php
public function __construct() {
	if(isset($_GET['s']) && $_GET['s'] != '') {
		$safeQuery = mysql_real_escape_string($_GET['s']);
		$theQuery = "SELECT * from parts WHERE part_num LIKE '%$safeQuery%' OR dealer LIKE '%$safeQuery%' OR retail LIKE '%$safeQuery%' OR uom LIKE '%$safeQuery%' OR page LIKE '%$safeQuery%' OR product_desc LIKE '%$safeQuery%'";
	} else {
		$theQuery = "SELECT * from parts";
	}
	$res = mysql_query($theQuery);
	$this->numRows = mysql_num_rows($res);
	$i = 0;
	while ($result = mysql_fetch_array($res)) {
		$this->ResultArray[$i] = $result;
		$i++;
	}
}

 

The starting query does not have any ORDER BY term in it, so you just get the rows in the order that they are stored in the table. You should probably add an ORDER BY term to both queries so that your product information is retrieved in some specific order, such as alphabetical by product name.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.