Jump to content

How do I select multiple rows?


jamesxg1

Recommended Posts

Hiya peeps,

 

Here's my search code.

 

     function getcid($cid) {
        $cid = mysql_real_escape_string(trim(addslashes($cid)));
        $cmp = "SELECT `companyid` FROM `uploadedcompanylogos` WHERE `username` = '$cid'";
        $rcmp = mysql_query($cmp);
        
        if($rcmp):
        while($c = mysql_fetch_assoc($rcmp)):
        return $c['companyid'];
        endwhile;
        endif;
    }
    
if(!isset($_REQUEST['key']) OR empty($_REQUEST['key'])):
echo 'No search criteria entered.';
exit;
endif;

if(isset($_POST['key'])):
$key = mysql_real_escape_string(trim(addslashes($_POST['key'])));
elseif (isset($_GET['key'])):
$key = mysql_real_escape_string(trim(addslashes($_GET['key'])));
endif;

echo '<table id="theTable" cellpadding="0" cellspacing="0" class="sortable-onload-3 no-arrow rowstyle-alt colstyle-alt paginate-10 max-pages-7 paginationcallback-callbackTest-calculateTotalRating paginationcallback-callbackTest-displayTextInfo sortcompletecallback-callbackTest-calculateTotalRating">';
echo '<tfoot>';
echo '<tr>';
    echo '<td colspan="6">This information is propery of Shawaghir and should remain only on this site.</td>';
echo '</tr>';
echo '</tfoot>';
echo '<thead>';
echo '<tr>';
				echo '<th class="date" scope="col">Company</th>
				<th scope="col">Location</th>
				<th scope="col">Title</th>
				<th scope="col">Description</th>
				<th scope="col">Type</th>
				<th scope="col">Salary</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';

$cud = "SELECT * FROM `jobs` WHERE `approval` = '0' AND `delete` = '0' AND `id` LIKE '%$key%' OR `company` LIKE '%$key%' OR `location` LIKE '%$key%' OR `industry` LIKE '%$key%' OR `jobtype` LIKE '%$key%' OR `experience` LIKE '%$key%' OR `education` LIKE '%$key%' OR `careerlevel` LIKE '%$key%' OR `salary` LIKE '%$key%' OR `description` LIKE '%$key%' OR `title` LIKE '%$key%' OR `employername` LIKE '%$key%' OR `employerphone` LIKE '%$key%'";
$displaycu = mysql_query($cud);

if($displaycu):
	if(mysql_num_rows($displaycu) == 0):
echo '<tr class="alt">';
    echo '<td>No Records</td>';
    echo '<td class="sized1">No Records</td>';
    echo '<td class="sized2"><i>No Records</i></td>';
    echo '<td class="sized3">No Records</td>';
    echo '<td class="sized3">No Records</td>';
    echo '<td class="sized3">No Records</td>';
echo '</tr>';
else:
while($cu = mysql_fetch_assoc($displaycu)):
    
echo '<tr class="alt">';
    echo '<td class="sized1"><a href="companyprofile.php?companyid=' . getcid($cu['username']) . '">' . $cu['company'] . '</a></td>';
    echo '<td class="sized1">' . $cu['id'] . '</td>';

    echo '<td class="sized2"><a href="job.php?jobid=' . $cu['id'] . '">' . truncate($cu['title'], '15') . '</a></td>';

echo '<td class="sized3">' . truncate($cu['description'], '15') . '</td>';
echo '<td class="sized3">' . $cu['jobtype'] . '</td>';
    echo '<td class="sized3">£' . $cu['salary'] . '</td></tr>';
endwhile;
endif;
  else:
  	echo '<tr class="alt">';
    echo '<td>ERROR</td>';
    echo '<td class="sized1">ERROR</td>';
    echo '<td class="sized2"><i>ERROR</i></td>';
    echo '<td class="sized3">ERROR</td>';
    echo '<td class="sized3">ERROR</td>';
echo '</tr>';
  endif;
  echo '</tbody>';
  echo '</table>';

 

I have made the script search various fields but its not completing the `delete` and `approval` part of the query. Anyone have any ideas why ?

 

Many thanks

 

James.

Link to comment
https://forums.phpfreaks.com/topic/195222-how-do-i-select-multiple-rows/
Share on other sites

it might be a lack of clarify the OR statements... try this:

 

 

$cud = "SELECT * FROM `jobs` WHERE `approval` = '0' AND `delete` = '0' AND (`id` LIKE '%$key%' OR `company` LIKE '%$key%' OR `location` LIKE '%$key%' OR `industry` LIKE '%$key%' OR `jobtype` LIKE '%$key%' OR `experience` LIKE '%$key%' OR `education` LIKE '%$key%' OR `careerlevel` LIKE '%$key%' OR `salary` LIKE '%$key%' OR `description` LIKE '%$key%' OR `title` LIKE '%$key%' OR `employername` LIKE '%$key%' OR `employerphone` LIKE '%$key%' )";

 

Also, echo "$key" and make sure its properly set

 

 

it might be a lack of clarify the OR statements... try this:

 

 

$cud = "SELECT * FROM `jobs` WHERE `approval` = '0' AND `delete` = '0' AND (`id` LIKE '%$key%' OR `company` LIKE '%$key%' OR `location` LIKE '%$key%' OR `industry` LIKE '%$key%' OR `jobtype` LIKE '%$key%' OR `experience` LIKE '%$key%' OR `education` LIKE '%$key%' OR `careerlevel` LIKE '%$key%' OR `salary` LIKE '%$key%' OR `description` LIKE '%$key%' OR `title` LIKE '%$key%' OR `employername` LIKE '%$key%' OR `employerphone` LIKE '%$key%' )";

 

Also, echo "$key" and make sure its properly set

 

Spot on, cheers mate.

 

Many thanks

 

James.

Archived

This topic is now archived and is closed to further replies.

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