AllSeoHelp.com
Search the Entire Site
  • PHP
  • JavaScript
  • CSS
  • HTML

PHP - Multi-sql Query






Topic

Multi-sql Query

View Content
Hi Chaps,

I'm trying to put together a Nested Set Model (Hierarchical Data), but I have having problems when it comes to deleting/updating the 'nested' table.

I'm using this as a guide:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

But when trying to run a query, such as:

SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1
FROM nested_category
WHERE name = 'GAME CONSOLES';

DELETE FROM nested_category WHERE lft BETWEEN @myLeft AND @myRight;

UPDATE nested_category SET rgt = rgt - @myWidth WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft - @myWidth WHERE lft > @myRight;


I get a MySQL syntax error.

This code works fine in something such as Windows Command Prompt, but not in PHP.

Is there a special way to run multiple queries in 1 PHP script?

Many thanks



Similar Tutorials

Multi-sql Query
Mysql Multi-query Insert
Complex Query Help: Multiple Fields & Multi-select List Boxes
Php Mysql Query Error - Only Shows In My Php Script Not On Direct Query?
Mysql Query Doesn't Work. [insert Query]
Phpmyadmin Query Works, But Php Query Doesn't...
Affixing Form Get Query To End Of Existing Query?
Perform Query On Previous Query Data
2nd Sql Query Also Returning Results From 1st Query
Php Query Failing Despite Valid...um...query.
Multi Url Browsing
Multi Table If Then
Multi Insert
Multi Form
Multi-checker
Multi Languege
Session Vars Loaded From Mssql Query Drop, Those Loaded From Mysql Query Stick
Multi Dimensional Arrays
Multi-dimensional Array Help
Multi-moderation Tool
Multi Page Inbox Help
Need Multi Dimensional Array Help
Search Multi Dim Array
Can't Delete Multi Records From Db With Php
Sms Multi-message Parsing






Multi-sql Query

Similar Tutorials View Content
Hi Chaps,

I'm trying to put together a Nested Set Model (Hierarchical Data), but I have having problems when it comes to deleting/updating the 'nested' table.

I'm using this as a guide:
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

But when trying to run a query, such as:

SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1
FROM nested_category
WHERE name = 'GAME CONSOLES';

DELETE FROM nested_category WHERE lft BETWEEN @myLeft AND @myRight;

UPDATE nested_category SET rgt = rgt - @myWidth WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft - @myWidth WHERE lft > @myRight;


I get a MySQL syntax error.

This code works fine in something such as Windows Command Prompt, but not in PHP.

Is there a special way to run multiple queries in 1 PHP script?

Many thanks


Mysql Multi-query Insert

Similar Tutorials View Content

Complex Query Help: Multiple Fields & Multi-select List Boxes

Similar Tutorials View Content
I need some help with the query for a form that selects values across multiple columns, and allow users to select multiple values in several columns.

     http://brinsterinc.com/tpa/tpasearch.php

I assume you build the where clause for the sql by determining if there is an option value has been selected in the single-value select boxes.

But how do I handle the multi-select list boxes?

I'm desperate for help!  Need to get somewhere with this over the weekend!

TIA!


Php Mysql Query Error - Only Shows In My Php Script Not On Direct Query?

Similar Tutorials View Content
Here is my code:
// Start MySQL Query for Records
$query = "SELECT codes_update_no_join_1b" .
"SET orig_code_1 = new_code_1,
       orig_code_2 = new_code_2" .
"WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)";
$results = mysql_query($query) or die(mysql_error());
// End MySQL Query for Records


This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this???

Code: [Select]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1




Mysql Query Doesn't Work. [insert Query]

Similar Tutorials View Content
If you also have any feedback on my code, please do tell me. I wish to improve my coding base.

Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference.

Code:

  Code: [Select]
mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)");
Full code:

Code: [Select]
<?php
include_once("includes/config.php");
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><? $title; ?></title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
 
<div id="wrap">
 
<div id="header">
<h1><? $title; ?></h1>
<h2><? $description; ?></h2>
</div>
 
<? include_once("includes/navigation.php"); ?>
 
<div id="content">
<div id="right">
<h2>Create</h2>
<div id="artlicles">
<?php
 
if(!$_SESSION['user'])
{
 
        $username = mysql_real_escape_string($_POST['username']);
        $password = mysql_real_escape_string($_POST['password']);
        $name = mysql_real_escape_string($_POST['name']);
        $server_type = mysql_real_escape_string($_POST['type']);
        $description = mysql_real_escape_string($_POST['description']);
 
        if(!$username || !$password || !$server_type || !$description || !$name)
        {

        echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>";
        echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'>
       
        <option value='Any'>Any</option>
        <option value='PvP'>PvP</option>
        <option value='Creative'>Creative</option>
        <option value='Survival'>Survival</option>
        <option value='Roleplay'>RolePlay</option>
       
        </select></td></tr>
       
        <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>";
        echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>";
        }
        elseif(strlen($password) < 8)
        {
        echo "Password needs to be higher than 8 characters!";
        }
        elseif(strlen($username) > 13)
        {
                echo "Username can't be greater than 13 characters!";
        }
        else
        {
                $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1");
               
                if(mysql_num_rows($check1) < 0)
                {
                        echo "Sorry, there is already an account with this username and/or server name!";
                }
                else
                {
                        $ip = $_SERVER['REMOTE_ADDR'];

                        mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)");
                        echo "Server has been succesfully created!";
                }
        }
       
}
else
{
        echo "You are currently logged in!";
}
 
?>
</div>
</div>
 
<div style="clear: both;"> </div>
</div>
 
<div id="footer">
<a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop
</div>
</div>
 
</body>
</html>



Phpmyadmin Query Works, But Php Query Doesn't...

Similar Tutorials View Content
I'm trying to update every record where one field in a row is less than the other. The code gets each row i'm looking for and sets up the query right, I hope I combined the entire query into one string each query seperated by a ; so it's like
UPDATE `table` SET field2= '1' WHERE field1= '1';UPDATE `table` SET field2= '1' WHERE field1= '2';UPDATE `table` SET field2= '1' WHERE field1= '3';UPDATE `table` SET field2= '1' WHERE field1= '4';UPDATE `table` SET field2= '1' WHERE field1= '5';
this executes properly if i run the query in phpMyAdmin, however when I run the query in PHP, it does nothing... Any advice?


Affixing Form Get Query To End Of Existing Query?

Similar Tutorials View Content
Say I have this query:

site.com?var=1

..I have a form with 'var2' field which submits via get.

Is there a way to produce:

site.com?var=1&var2=formdata

I was hoping there would be a quick way to affix, but can't find any info. Also, the query could sometimes be:

site.com?var2=formdata&var=1

I would have to produce:

site.com?var2=updatedformdata&var=1

Is my only option to further parse the query?


Perform Query On Previous Query Data

Similar Tutorials View Content
I was just wondering if it's possible to run a query on data that has been returned from a previous query?  For example, if I do

Code: [Select]
$sql = 'My query';
$rs = mysql_query($sql, $mysql_conn);

Is it then possible to run a second query on this data such as

Code: [Select]
$sql = 'My query';
$secondrs = mysql_query($sql, $rs, $mysql_conn);

Thanks for any help


2nd Sql Query Also Returning Results From 1st Query

Similar Tutorials View Content
What would be the correct way to close a mysql query?

At current the second query below returns results from the 1st query AND the 2nd query
The 3rd query returns results from the 1st, 2nd and 3rd query.
 etc etc.

At the moment I get somthing returned along the lines of...

QUERY 1 RESULTS
Accommodation 1
Accommodation 2
Accommodation 3

QUERY 2 RESULTS
Restaurant 1
Restaurant 2
Restaurant 3
Accommodation 1
Accommodation 2
Accommodation 3

QUERY 3 RESULTS
Takeaways 1
Takeaways 2
Takeaways 3
Restaurant 1
Restaurant 2
Restaurant 3
Accommodation 1
Accommodation 2
Accommodation 3

Code: [Select]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php 
  include($_SERVER['DOCUMENT_ROOT'].'/include/db.php');
?>
<title>Untitled Document</title>
<style type="text/css">
<!--
-->
</style>
<link href="a.css" rel="stylesheet" type="text/css" />
</head><body>
<div id="listhold">

<!------------------------------------------------------------------------------------------------------------------------------------------------------>

<div class="list"><a href="Placestostay.html">Places To Stay</a><br />
<?php
$title ="TITLE GOES HERE";
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Accommodation' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . $nt[$i] . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>
</div>

<!------------------------------------------------------------------------------------------------------------------------------------------------------>

<div class="list"><a href="Eatingout.html">Eating Out</a><br />
<?php
$title ="TITLE GOES HERE";
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . $nt[$i] . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>
</div>

<!------------------------------------------------------------------------------------------------------------------------------------------------------>

<div class="list"><a href="Eatingin.html">Eating In</a><br />
<?php
$title ="TITLE GOES HERE";
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Takeaways' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . $nt[$i] . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>
</div>

<!------------------------------------------------------------------------------SKILLED TRADES BELOW--------------------------------------------------->

<div class="list"><a href="Skilledtrades.html">Skilled Trades</a><br/>
<?php
$title ="TITLE GOES HERE";
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Skilled Trades' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . $nt[$i] . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>
</div>


Php Query Failing Despite Valid...um...query.

Similar Tutorials View Content
here's the code:

Code: [Select]
$companyName = 'big company';
$address1 = 'big bay #8';
$address2 = 'some big warehouse';
$city = 'big city';
$province = 'AB';
$postalCode = 'T1T0N0';
$phone = '0123456789';
$email2 = 'bigKahuna@bigKahuna.edu';

$query = "INSERT INTO clients (
                   companyName, address1, address2, city, province, postalCode, phone, email)
                 VALUES ( ".
                    $companyName.",".$address1.",".$address2.",".$city.",".$postalCode.",".$phone.",".$email2.")";

$result = mysql_query($query, $connexion);

if ($result)
{
// Success!
echo "Fabulous!  check the DB, we did it! :D<br>";
?>

<pre>
<?php
print_r($result);
?>
</pre>

<?php
} else {
// Fail!
echo"CRAAAAAPP!  something went wrong.  FIX IT!  :P<br>";
echo mysql_error();
}

if (isset($connexion)) { mysql_close($connexion); }
i copied it over from an old *working* file to illustrate how a simple INSERT works.

this is the error i get:

Code: [Select]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'company,big bay #8,some big warehouse,big city,T1T0N0,0123456789,bigKahuna@bigKa' at  line 4
looks completely valid to me.  all the database table elements are set to VARCHAR(80), so it can't be a space/type issue...

halp! 

WR!


Multi Url Browsing

Similar Tutorials View Content
Hi guys
I got an issue that when a link on the site is loading, the other links does not load until the previous is complete but it will work if i try on 2 different browsers. How can i browse multiple links silmultanously?
Thanks


Multi Table If Then

Similar Tutorials View Content
hello all, i have been sitting here googleing and googling but i can't seem to find what im looking for.

i am tring to create a personal site that lets me note services i do for my cars. I have multiple tables (cars, color, mfg, ...) in the main table cars i insted of putting the color black i put and int(11) of 1 which is suppose to "if statement" to the table colors and produce the correct color. same for mfg. although nothing i have tried has helped i always just have the else of the if echoed out.

i have heard of union and join left right i am so unsure of what is need any insite would be useful.

thanks in advance.


Multi Insert

Similar Tutorials View Content
hello,  is there a way to insert something 17 times into a database and change the 3rd field one at a time (from 1-17)?

Code: [Select]
$sql = "INSERT INTO picks VALUES (
NULL,
'" . mysql_real_escape_string($userid) ."',
'" . mysql_real_escape_string($weekid) ."',
'" . mysql_real_escape_string($pickid) ."'
)";
  mysql_query($sql) or die('Error, Check you fields and try again.');


Multi Form

Similar Tutorials View Content
hi , i want to make 5 forms with 1 submit button , how i do that?
thanks , Mor.


Multi-checker

Similar Tutorials View Content
Hello friends,

I've tried to search over the Internet but didn't found any tutorial how to do the following :-

let say we have form with input username and input email just 2 field

HTML Code

Code: [Select]
<form>
<table>
<tr>
<td>Username :</td>
<td><input id="username" size="20" type="text" name="username"></td>
</tr>
<tr>
<td>Email :</td>
<td><input id="email" size="20" type="text" name="email"></td>
</tr>
</table>
</form>

As you can see no submit button cause we will only check out if username and/or email is not stored already, by using ajax

My problem : i can only check out for username (1 field) but i can not check for 2 fields or more and i want to know how to apply it for 2 fields (username and email)

Here is my idea for only one field (username)

I'll add in the HTML code  this

Code: [Select]
<td><div id="status"></div></td>
and will add this java code

Code: [Select]
<SCRIPT type="text/javascript">
pic1 = new Image(16, 16);
pic1.src = "loader.gif";
$(document).ready(function(){
$("#username").change(function() {
var usr = $("#username").val();
if(usr.length >= 4)
{
$("#status").html('<img src="loader.gif" align="absmiddle">&nbsp;Checking availability...');
$.ajax({
type: "POST",
url: "check.php",
data: "username="+ usr,
success: function(msg){
$("#status").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
{
$("#username").removeClass('object_error');
$("#username").addClass("object_ok");
$(this).html('&nbsp;<img src="tick.gif" align="absmiddle">');
}
else
{
$("#username").removeClass('object_ok');
$("#username").addClass("object_error");
$(this).html(msg);
}
});
}
});
}
else
{
$("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
$("#username").removeClass('object_ok');
$("#username").addClass("object_error");
}
});
});
</SCRIPT>

Explain : it will get the input of username and will send it to check.php

Now check.php code (should have all usernames that will compare with it)

Code: [Select]
<?php
if(isSet($_POST['username']))
{
$usernames = array('john','michael','terry', 'steve', 'donald');
$username = $_POST['username'];
if(in_array($username, $usernames))
{
echo '<font color="red">The username<STRONG>'.$username.'</STRONG> is already in use.</font>';
}
else
{
echo 'OK';
}
}
?>

Now it is very clear , if will automatic check the username

now my problem is how to apply it for also email


Multi Languege

Similar Tutorials View Content
common.php
Code: [Select]

<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_SESSION['lang'] = $lang;

setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}

switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;

  case 'de':
  $lang_file = 'lang.de.php';
  break;

  case 'el':
  $lang_file = 'lang.el.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>
ip2locationlite.class.php
Code: [Select]
<?php
final class ip2location_lite{
protected $errors = array();
protected $service = 'api.ipinfodb.com';
protected $version = 'v3';
protected $apiKey = '';

public function __construct(){}

public function __destruct(){}

public function setKey($key){
if(!empty($key)) $this->apiKey = $key;
}

public function getError(){
return implode("\n", $this->errors);
}

public function getCountry($host){
return $this->getResult($host, 'ip-country');
}

public function getCity($host){
return $this->getResult($host, 'ip-city');
}

private function getResult($host, $name){
$ip = @gethostbyname($host);

if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){
$xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml');

try{
$response = @new SimpleXMLElement($xml);

foreach($response as $field=>$value){
$result[(string)$field] = (string)$value;
}

return $result;
}
catch(Exception $e){
$this->errors[] = $e->getMessage();
return;
}
}

$this->errors[] = '"' . $host . '" is not a valid IP address or hostname.';
return;
}
}
?>



index.php

Code: [Select]
<?php
include_once('ip2locationlite.class.php');
 
//Set geolocation cookie
if(!$_COOKIE["geolocation"]){
  $ipLite = new ip2location_lite;
  $ipLite->setKey('*****************');
 
  $visitorGeolocation = $ipLite->getCountry($_SERVER['REMOTE_ADDR']);
  if ($visitorGeolocation['statusCode'] == 'OK') {
    $data = base64_encode(serialize($visitorGeolocation));
    setcookie("geolocation", $data, time()+3600*24*7); //set cookie for 1 week
  }
}else{
  $visitorGeolocation = unserialize(base64_decode($_COOKIE["geolocation"]));
}
var_dump($visitorGeolocation);
?>


im using this http://ipinfodb.com/

in index.php i got this message

array(5) { ["statusCode"]=> string(2) "OK" ["statusMessage"]=> string(0) "" ["ipAddress"]=> string(13) "94.68.211.211" ["countryCode"]=> string(2) "GR" ["countryName"]=> string(6) "GREECE" }

how to switch automatic if GR go to index.php?lang=el
if DE go to  index.php?lang=de etc...





Session Vars Loaded From Mssql Query Drop, Those Loaded From Mysql Query Stick

Similar Tutorials View Content
I'm restarting this under a new subject b/c I learned some things after I initially posted and the subject heading is no longer accurate.

What would cause this behavior - when I populate session vars from a MYSQL query, they stick, if I populate them from an MSSQL query, they drop.

It doesn't matter if I get to the next page using a header redirect or a form submit.  I have two session vars I'm loading from a MYSQL query and they remain, the two loaded from MSSQL disappear. 

I have confirmed that all four session vars are loading ok initially and I can echo them out to the page, but when the application moves to next page via redirect or form submit, the two vars loaded from MSSQL are empty. 

Any ideas?




Multi Dimensional Arrays

Similar Tutorials View Content
Basically what I want to do is create an array of inheritance.  so here is the levels
Owner->Admin->moderator->User->guest

owner has all the abilities of admin, moderator, user and guest..

So I want to be able to sort through them and end with an array like this
Code: [Select]
$array['Owner'] = array('Admin', 'Moderator', 'User', 'Guest');
Currently my code works sort of. Basically Admin is only set to inherit Moderator. Moderator only inherits User. So this code works but only to 2 levels. I don't want to add a billion foeachs within each other for each level(currently 4) but I might add more roils so then I would have to add more foreachs. There must be a magic way to do this. Any feedback is appreciated!

Code: [Select]
<?PHP

$sql = 'SELECT * FROM '.self::$Config['PERMISSIONS']['Database'].'.permissions_inheritance';

$result = DB::Query($sql);
while($row = DB::fetch($result)){
if($row['type'] == '0'){
$group_i[$row['child']][] = $row['parent'];
}elseif($row['type'] == '1'){
$user_i[$row['child']][] = $row['parent'];
}
}

//echo count($group_i);
print_r($group_i);
$groups = array();


foreach($group_i as $Key=>$Value){
foreach($Value as $K=>$V){
$new_array[$Key][] = $V;
if(isset($group_i[$V]) && is_array($group_i[$V])){
foreach($group_i[$V] as $Q=>$A){
if(is_array($A)){
foreach($A as $C=>$X){
$new_array[$Key][] = $X;
}
}else{
$new_array[$Key][] = $A;
}
}
}
}

}
Let me know if you have any questions! I hope you enjoy the challenge lolol


Multi-dimensional Array Help

Similar Tutorials View Content
I am having a hell of a time getting this to work. I need the keys in an array to be specific, not a sequential number or a row in my database. I need to add to the array through each loop of my while() statement. This code does it, but does not use the keys I specify, after the first entry, it starts assigning numbers to keys. Any guidance would be great.

<?php
require_once ('includes/config.php');
require_once ('includes/connect.php');

$echoarray = array();
$resultsql = mysql_query("SELECT * FROM clients")or die(mysql_error());
while($row = mysql_fetch_array($resultsql)){
    if(empty($echoarray)){
$echoarray = array(
'id' => $row['ID'],
'name' => $row['First_Name'] . " " . $row['Last_Name'],
'price' => $row['Status'],
'number' => $row['Sex'],
'address' => $row['Phys_Street'],
'company' => $row['Agency'],
'desc' => $row['Notes'],
'age' => $row['Date_Birth'],
'title' => $row['Occupation'],
'phone' => $row['Phone'],
'email' => $row['Email'],
'zip' => $row['Phys_Zip'],
'country' => $row['Phys_City']
);
}
else
{
array_push($echoarray,
$echoarray['id'] = $row['ID'],
$echoarray['name'] = $row['First_Name'] . " " . $row['Last_Name'],
$echoarray['price'] = $row['Status'],
$echoarray['number'] = $row['Sex'],
$echoarray['address'] = $row['Phys_Street'],
$echoarray['company'] = $row['Agency'],
$echoarray['desc'] = $row['Notes'],
$echoarray['age'] = $row['Date_Birth'],
$echoarray['title'] = $row['Occupation'],
$echoarray['phone'] = $row['Phone'],
$echoarray['email'] = $row['Email'],
$echoarray['zip'] = $row['Phys_Zip'],
$echoarray['country'] = $row['Phys_City']
);
    
}

Any Ideas?


Multi-moderation Tool

Similar Tutorials View Content
How would I go about making a small feature for my moderators that allows them to select multiple threads while viewing a forum then take action? All I need is an idea of how I would do this. Wouldn't I use the explode() function?

Example: http://i490.photobucket.com/albums/rr267/brannenclass/ex.png


Multi Page Inbox Help

Similar Tutorials View Content
So far with my inbox I got it to grab the message and display them in order by most recently sent.
but now I want to add multiple inbox pages and set a limit on how many messages are on each page. I cant think of the idea behind of doing it. If someone could kindly guide me please. I know i need to use tokens in the link for each page but i dont understand the concept behind having newest messages to oldest showing up on each page




Code: [Select]
<?php 

$take3 = "SELECT time_offset FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; 
$take2 = mysql_query($take3) or die(mysql_error());
$take1 = mysql_fetch_array($take2);

$result = mysql_query("SELECT * FROM pm WHERE id = '".($_SESSION['user_id'])."' ORDER BY time DESC");

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {

$pm_id = $row['pm_id'];
$msggoauld = $row['sentfrom'];
$subject = $row['subject'];
$recieved = $row['time'];

$time = ($recieved + $take1['time_offset']);

                date_default_timezone_set('UTC');

                               $offset = date('m/d/Y/H:i:s', $time);          
            
?>
      <tr>
      <td><center><input type="checkbox" name="messageid" class="select-all-box" value="327990" ?></center></td>

    </label></td>
       
    <td><center><a href="search_goaulds.php?goauld=<?php echo $msggoauld; ?>"><?php echo $msggoauld ?></a></center></td> 
   
       <td><center><a href="view.php?pm_id=<?php echo $pm_id; ?>"><?php echo $subject ?></a></center></td>
       
    <td><center><?php echo $offset ?></center></td>
     
    </tr>
        <?php } // while loop 
        ?>
    </table>
    <p>&nbsp;</p>
  </center>
  </p>
</form> 


Need Multi Dimensional Array Help

Similar Tutorials View Content
I have been trying to solve this problem for a few days now and can't seem to work it out. I'm sure i'm missing some simple point..
I am using a mysql PDO fetch to return 2 fields in each row and then put them into an array of their own:
foreach ($st->fetchAll() as $row){
$subs[] = array($row['subscriber'],$row['plant']);
Some of the rows share the same $row[0], which is the 'subscriber' field. What I want to do is make up another array with each smaller array having a single, unique $row[0] and any number of added 'plant' fields following (e.g $row[1],$row[2] etc).
I've tried all sorts of ways to achieve this but am at a loss. Would someone be able to point me in the right direction ? Thanks.


Search Multi Dim Array

Similar Tutorials View Content
Whats the most efficient way of searching within a multi dimensional array?

My Array =

Array ( => Array ( => Item 1 [title] => Item 1 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) [1] => Array ( => Item 2 [title] => Item 2 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) )

String to find = '21'

If (MY ARRAY contains STRING TO FIND) {}

Clearly in this case there are several '21' (s) so if I only wanted to search the [eventDay] keys...would there be a fast effective and efficient manner?


Thoughts and help gratefully received.

Will


Can't Delete Multi Records From Db With Php

Similar Tutorials View Content
Hi Guys, How come i am unable to delete a record with the same id from multi records with the following php code?

$rid = "SELECT month_ID FROM monthA WHERE userID = '".$_POST['userID']."' AND thisMonth = '".$_POST['month']."' AND thisYear = '".$_POST['year']."'";
$rid_month = mysql_query($rid);
            $row = mysql_fetch_array($rid_month);
            $month_ID = $row["month_ID"];

$rid = "SELECT * FROM monthB WHERE month_ID = '$month_ID'";
            $rid_month = mysql_query($rid);
$row = mysql_fetch_array($add_member);
            while ($row = mysql_fetch_array($rid_month)) {
$month_ID = $row["month_ID"];
$rid = "DELETE FROM monthBB WHERE month_ID = '$month_ID' ";
$result =  mysql_query($rid);
}
$rid = "SELECT * FROM monthC WHERE month_ID = '$month_ID' ";
            $rid_month = mysql_query($rid);
            while ($row = mysql_fetch_array($rid_month)) {
$month_ID = $row["month_ID"];
$rid = "DELETE FROM monthCC WHERE month_ID = '$month_ID' ";
$result =  mysql_query($rid);
}
$rid = "DELETE FROM monthA WHERE month_ID = '$month_ID' ";
$result =  mysql_query($rid);

I have tried a number of ways without any luck. How ever if i use this code?
mysql_query("DELETE FROM monthA WHERE month_ID = '$month_ID'");
It allows me to delete one row from one table only. Please advise


Sms Multi-message Parsing

Similar Tutorials View Content
I'm working on a PHP SMS gateway of sorts. I have the txt message saved to the variable $message but I have a small problem with multi-message text messages..

When most phones send multiple messages as one, they include a (X/Y) before the message.. X indicating which message it is out of Y messages.

A rough example:

Quote

the first message comes through:
$message = "(1/2) This is a multimessage text message that";

the second message comes through:
$message = "(2/2) will use more than one message to send";




I would like to be able to parse these... as such:

Quote

if ($message == "(1/Y)") {
// Save first message
} elseif ($message == "(2+/Y)") {
// Append to original message
// This number can be anything 2 and above
} else {
// One message text, so save it like normal
}



If I can figure this out, I'll write a tutorial in a few days on how to set up a free php sms gateway for your own project! Including how/where to get a free number to use!



Privacy