Archive

Posts Tagged ‘select from’

Sql Query

June 18th, 2009 Comments off

I need this query completed right away. I am not able to provide access or give you a copy of any part of the database. I am online right now on MSN Messenger to work with you though on getting this done right away. Please only bid if you understand the project. If you have any questions message.

This project uses 5 queries.

1. Retrieve the Group Items
2. Check each individual item combination
3. Check inventory for each individual item combination
4. If IN STOCK is greater than zero run query4 if not run query5.

QUERY1:
SELECT * FROM ITEMS
WHERE CUSTCHAR3 LIKE ‘%ST%’ AND MATRIX_ITEM_TYPE = ’0′

*** FOREACH RESULT FOR OF QUERY1 RUN QUERY2: ***

QUERY2:
SELECT * FROM MATRIX_ITEMS
WHERE MATRIX_GROUP_CODE = ”)

*** FOREACH RESULT OF QUERY2 RUN QUERY 3. ***

QUERY3:
SELECT * FROM ITEMS
WHERE Q_ON_RESER < QTY_STK AND QUERY2.MATRIX_ITEMS.ITEM_CODE

IF QUERY3 RETURNS A RESULT UPDATE INSTOCK BY ’1′

** FINALLY IF IN STOCK IS GREATER THAN 0 RUN QUERY 4 OTHERWISE RUN QUERY 5 **

QUERY4:

INSERT INTO ITEM_EQ
(ACTIVE,EQ_CODE,ITEMNO,DESCRIPT,SELLPRIC_O,CREATED_BY,CREAT_DATE,WEB_ACTIVE,CATEGORY,CUSTCHAR3,MEAS_CODE)
SELECT ‘T’,Items.ITEMNO + ‘-2′,ITEMS.ITEMNO,ITEMS.DESCRIPT,’F',’SUP32′,GETDATE(),’T',CASE
WHEN Items.Category LIKE ‘BB%’ THEN ‘BUCKLES’
ELSE ‘TLS’
END
,’[ST]‘,’EA’
FROM ITEMS
WHERE CUSTCHAR3 LIKE ‘%ST%’ AND ACTIVE = ‘T’ AND WEB_ACTIVE = ‘T’
AND ITEMS.ITEMNO = ITEMS.ITEMNO (FROM QUERY1)
and not exists (select * from ITEM_EQ Where EQ_CODE = ITEMS.ITEMNO (FROM QUERY1) + ‘-2′);

QUERY5:

DELETE FROM ITEM_EQ
WHERE EXISTS
( select ITEMS.ITEMNO
from ITEMS
where ITEMS.ITEMNO = ITEMS.ITEMNO (FROM QUERY1) AND ITEMS.QTY_STK = 0 AND ITEMS.CUSTLOG4 = ‘F’ AND CUSTCHAR3 LIKE ‘%ST%’ AND ITEM_EQ.CREATED_BY = ‘SUP32′);

Mysql Php Pagination Fix

March 29th, 2009 Comments off

Hello,

I have a script, it displays all active banners using pagination. Once the banner is clicked it doesn’t show up again. This works fine.

The issue:

For example I’m displaying 25 banners per page, I have over 1000 active banners so there are 102 pages.

If I click on the all 25 of the banners on page one and then leave the site, the next time I come back to the site they do not show. This works correctly. But here is the problem, when I come back to the site page one is blank, I have to move on to page 2 in order to see the next round of banners. So in other words it’s not moving the banners up to page one.

I need this fixed.

Here is the code if you think you want to tackle it.

[code]
<?php

session_start();

include "../header.php";

include "../config.php";

include "../style.php";
$uname=$_SESSION[uname];
if( session_is_registered("ulogin") ) {

$tbl_name="banners"; //your table name

// How many adjacent pages should be shown on each side?

$adjacents = 3;

/*

First get total number of rows in data table.

If you have a WHERE clause in your query, make sure you mirror it here.

*/

if( session_is_registered("ulogin") )

{

$query = "SELECT COUNT(*) as num FROM banners, banner_clicks WHERE banners.status=1 and banners.max>banners.shown AND banner_clicks.userid<>'".userid."' group by banners.id";

}

else

$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE status=1 and max>shown";

$ttlpag=mysql_query($query) or die (mysql_error());

$total_pages = mysql_fetch_array($ttlpag);

$total_pages = $total_pages[num];
$qn="select * from sat_banclicks where userid='$uname' group by bannerid";
$ns=mysql_query($qn);
$nk=mysql_num_rows($ns);
$total_pages=$total_pages-(2*$nk);
//echo $nk;

/* Setup vars for query. */

$targetpage = "bannerlinkview.php"; //your file name (the name of this file)

$limit = 25; //how many items to show per page

$page = $_GET['page'];

if($page)

$start = ($page - 1) * $limit; //first item to display on this page

else

$start = 1; //if no page var is given, set start to 0

/* Get data. */

if( session_is_registered("ulogin") )

{

$sql = "SELECT banners.id as id, banners.name as name, banners.bannerurl as bannerurl, banners.targeturl as targeturl, banners.userid as userid, banners.shown as shown, banners.clicks as clicks, banners.max as max, banners.added as added FROM banners, banner_clicks WHERE banners.status=1 and banners.max>banners.shown AND banner_clicks.userid<>'".userid."' group by banners.id LIMIT $start, $limit";

}

else

{

$sql = "SELECT * FROM banners WHERE status=1 and max>shown LIMIT $start, $limit";

}

$result = mysql_query($sql) or die (mysql_error());

if(!mysql_num_rows($result))

{

$result = mysql_query ("SELECT * FROM banners WHERE status=1 and max>shown LIMIT $start, $limit");

}

/* Setup page vars for display. */

if ($page == 0) $page = 1; //if no page var is given, default to 1.

$prev = $page - 1; //previous page is page - 1

$next = $page + 1; //next page is page + 1

$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.

$lpm1 = $lastpage - 1; //last page minus 1

/*

Now we apply our rules and draw the pagination object.

We're actually saving the code to a variable in case we want to draw it more than once.

*/

$pagination = "";

if($lastpage > 1)

{

$pagination .= "<div class="pagination">";

//previous button

if ($page > 1)

$pagination.= "<a href="$targetpage?page=$prev">

Categories: MySQL, PHP Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Bear