Jump to content

Comparing Values


White_Lily

Recommended Posts

Hi, I have been asked to sort out a problem with related pages where the CMS lets you add pages even if there some already set.

 

I have written a little validation where it checks if the page selected has already got related pages on it... however the script skips the validation and goes and inserts the new related pages anyway...

 

if(isset($_POST['addTest']))

{ 
// Get posted values
$category = mysql_real_escape_string($_POST['catSel']);
$product_category = mysql_real_escape_string($_POST['product_category']);

$getMultiple = select("sidebar_featured_pages", "*", "category = '$category'");
$check = mysql_fetch_assoc($getMultiple);

if($category == $check["catSel"]){
$msg .= generateMsg("Sidebar Pages creation failed, the page you selected already has pages set.");
}else{ 
$addTest = insert("sidebar_featured_pages", array("", $category, $product_category));

if($addTest){
$msg .= generateMsg("Sidebar Pages created successfully.", "success");
}else{
$msg .= generateMsg("Sidebar Pages creation failed, unable to access the database.");
}
}
}

 

Any ideas?

Link to comment
Share on other sites

select() is custom function:

 

function select($table, $rows = "*", $where = NULL, $order = NULL, $limit = NULL, $offset = NULL)
{
$queryString = "SELECT ".$rows." FROM ".$table;
if($where != null)
$queryString .= " WHERE ".$where;
if($order != null)
$queryString .= " ORDER BY ".$order;
if($limit != null)
$queryString .= " LIMIT ".$limit;
if($offset != null)
$queryString .= " OFFSET ".$offset;

$query = mysql_query($queryString);

// if query is successful
if($query)
return $query;
else
return false;
}

Link to comment
Share on other sites

Basically if the value of say... 10 is in catSel AND category, then I don't want them to be able to have related pages, but if the value isn't equal then they can have related pages.

 

It's like saying if someone registers to a website and they pick a username that has already been taken, then you wouldn't want them to have that username you would want them to pick something different - that's something similar to what i am trying to achieve.

Link to comment
Share on other sites

Right, I managed to find something that has finally worked!!

 

The code that gets the id's that have pages already set:

 

$allRel = select("sidebar_featured_pages", "*");

while($allRelRes = mysql_fetch_array($allRel)){
$usedCats[$allRelRes["category"]] = true;
}

 

The code that displays categories that haven't been used:

 

<select name="catSel" style="width: 300px;">
<?
$getCategories = select("pages", "id, name", "(page_switch = 1) AND (type = 2 OR type = 4 OR type = 5)");

while ($categories = mysql_fetch_array($getCategories))
{
if(!isset($usedCats[$categories['id']])){
echo "<option value='".$categories['id']."'>".$categories['name']."</option>";
}
}
?>
</select>

 

 

Thank for the help you all gave! x

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.