Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really

gwar3k1 posted:

Ah okay, sorry. If you look at my previous example, you can access each array item individually by using $row['fieldname']. Try the following:
Use default: instead of case else: and (edit - he had this right, but I'll leave the note in as it's useful for learners to keep in mind) remember that each case needs to end with break; or it will run the code of every case after it, a feature which in this case is used to run the same code for case 0 and 1. Also, just as an efficiency thing, it's better to set $elements = count($row) - 1 then use $elements in the loop because that way it only needs to run the count() function once.
php:
<?
// loop all returned rows
while($row = mysql_fetch_assoc($query)
{
  // loop all items within the $row array
  $elements = count($row) - 1;
  for(i = 0; i<=$elements; i++)
  {
    // conditional select based on index of $row array
    switch($i)
    {
      // first two indexes
      case 0:
      case 1:
        // output non-field cell
        break;
      // all other indexes
      default:
        // output field cell
        break;
    }
  }
}?>

DoctorScurvy fucked around with this message at 08:18 on Apr 26, 2010

Adbot
ADBOT LOVES YOU

the chip
Mar 10, 2002

Fun Shoe
I've been using the Shopp plugin for Wordpress, and my boss wanted me to make each products "Details and Specs" be a tabbed interface. The box for details and specs is unusably small, so I wrote a php script to take the info and split it into the 3 tabs he wants. For some reason, it seems like PHP is adding backslashes to the code in certain places (they seem to be in front of quotation marks mostly.) Why is it doing this?

php:
<?

<center><h2>Product Tab-ulator</h2></center>
<form action="formatter.php" method="post">
<div>
Product Info: (Product Details Tab)<br>
<textarea name="item_longdesc" rows="5" cols="80"><?php echo $_POST[item_longdesc?></textarea><br>
</div>
<div style="float: left;">
Specification name: (Specifications Tab, Left Column)<br>
<textarea name="item_desc" rows="30" cols="40"><?php echo $_POST[item_desc?></textarea><br>
</div>
<div style="float: left;">
Specification value:(Specifications Tab, Right Column)<br>
<textarea name="item_spec" rows="30" cols="70"><?php echo $_POST[item_spec?></textarea><br>
</div>
<div>
Updates Available:(Updates tab)<br>
<textarea name="item_updates" rows="30" cols="40"><?php echo $_POST[item_updates?></textarea><br>
<input type="submit" />
</div>
</form> 

<?php
    $header="<div class='tabber'><div class='tabbertab'><h2>Product Details</h2><p>"$header=$header$_POST[item_longdesc] . "</p></div><div class='tabbertab'><h2>Product Specifications</h2>";
$header=$header"<p><div style='min-height:500px;' ><div class='itemlist'>";
    //<div class='itemdesc'>40<br></div></p></div></div>
    
    $idesc=explode("\n"$_POST[item_desc]);
    $ispec=explode("\n"$_POST[item_spec]);
    foreach ($idesc as $item){
        $header =  $header "<b>".  $item "</b><br>";
    }
    $header=$header "</div> <div class='itemdesc'>";
    foreach ($ispec as $item){
        $header =  $header .  $item "<br>";
    }
    $header=$header "</div></div></div><div class='tabbertab'><h2>Product Updates</h2><p>" $_POST[item_updates] . "</p></div></div>";
    echo "<h2>Results - Do not use until you have hit the submit query button:<br><div style='background-color: #C4E5F3;'>";
    echo htmlspecialchars($header) . "</div>";
?>
    
?>

the chip fucked around with this message at 01:32 on Apr 26, 2010

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Dargor posted:

Hey Im sorry that this post breaks the tables. I went back to try to fix this, but the PHP code I posted actually ran on the preview page. Can either a mod fix this or someone tell me what to do to unbreak the tables with my post :(



php:
<?

// OH NOES! BREAKAGE!

?>

You have to something like this:

php:
<?
$header = "<div class='tabber'><div class='tabbertab'><h2>Product Details</h2><p>"; 
$header .= $_POST[item_longdesc] 
$header .= "</p></div><div class='tabbertab'><h2>Product Specifications</h2><p>";
$header .= "<div style='min-height:500px;' ><div class='itemlist'>";
?>
as PHP and CODE tags won't line wrap on the forums.

the chip
Mar 10, 2002

Fun Shoe
Thanks Lumpy.

EDIT: duh, stripslashes()

the chip fucked around with this message at 04:36 on Apr 26, 2010

gwar3k1
Jan 10, 2005

Someday soon

DoctorScurvy posted:

Use default: instead of case else: and remember that each case needs to end with break; or it will run the code of every case after it. Also, just as an efficiency thing, it's better to set $elements = count($row) - 1 then use $elements in the loop because that way it only needs to run the count() function once.
php:
<?
// loop all returned rows
while($row = mysql_fetch_assoc($query)
{
  // loop all items within the $row array
  $elements = count($row) - 1;
  for(i = 0; i<=$elements; i++)
  {
    // conditional select based on index of $row array
    switch($i)
    {
      // first two indexes
      case 0: break;
      case 1: break;
        // output non-field cell
        break;
      // all other indexes
      default:
        // output field cell
        break;
    }
  }
}?>

Yeah I didn't check the case else/default thing, I've been switching between languages all week and got confused. Good point about the count() usage.

I am curious though, I was showing how to fall through cases so that case 0 and case 1 run the same code (// output non-field cell). By including breaks isn't this preventing that feature, like you said or is it a case of them being in-line doesn't affect the fall through? I had the break for both of them below where the code (commented for simplicity) lies.

DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really

gwar3k1 posted:

I am curious though, I was showing how to fall through cases so that case 0 and case 1 run the same code (// output non-field cell). By including breaks isn't this preventing that feature, like you said or is it a case of them being in-line doesn't affect the fall through? I had the break for both of them below where the code (commented for simplicity) lies.
Right you are, I didn't even notice the break you put in there. You had that part correct to begin with and I apologise.

lactomangulation
Jan 29, 2009
I have a script that reads a file based on the query, and gets a random line from the file:

php:
<?

$filename = $_GET['q'];
if(preg_match('/^[a-z0-9]+$/i', $filename))
{
$items = array_map("trim", file($filename.".txt"));
$randomitem = $items[array_rand($items)];
}
else
{
$randomitem = '';
}
?>
If the above script is named mypage.php, then visiting mydomain.com/mypage.php?q=stuff1 will set $randomitem to a random line from stuff1.txt

Is there a better way to do something like this?

I'm aware of the issues about someone putting in "/.." or similar for the query to view files out of the current directory, thus I limited the query to alphanumerics. I don't mind if they enter in a filename and come across a different file, just that they shouldn't view anything outside of the current directory.

gibbed
Apr 10, 2006

As long as you're sanitizing the input file name it should be okay, although I would add a base path to the $filename and also check if the file exists too.

rugbert
Mar 26, 2003
yea, fuck you
I got my search feature (that I was trying to do before with WP) working near perfect, but this kills it:
code:
          
 AND post_id IN (SELECT post_id
                       FROM   wp_postmeta
                       WHERE  ( meta_key = 'Utilities'
                                AND meta_value LIKE '%Water%' ))
or this, where $searchAvail = '%-08-%'
code:
       AND post_id IN (SELECT post_id
                       FROM   wp_postmeta
                       WHERE  ( meta_key = 'Availability'
                                AND meta_value LIKE '%-$searchAvail-%' ))
it has the to be wildcards... I know for a fact the query returns real results (I used that exact code in terminal) but it doesnt work from php. I use backslashes to escape characters right? That doesnt seem to work.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums

Lumpy posted:

You have to something like this:

php:
<?
$header = "<div class='tabber'><div class='tabbertab'><h2>Product Details</h2><p>"; 
$header .= $_POST[item_longdesc] 
$header .= "</p></div><div class='tabbertab'><h2>Product Specifications</h2><p>";
$header .= "<div style='min-height:500px;' ><div class='itemlist'>";
?>
as PHP and CODE tags won't line wrap on the forums.

Though in all fairness this is loving awful and I cant think of a reason to have something like this in well templated PHP.

Pookster
Jul 4, 2007

drcru posted:

True, how do you guys do it? I've never tried before.

I whipped up a simple templating class a while back, this is it slightly modified:
php:
<?
/**
 * Simple templating engine.
 */
class TemplateRenderer {

    /**
     * @var array Key/Value pair array of variables.
     */
    protected $_variables;

    /**
     * Initialise.
     */
    public function __construct() {
        $this->_variables = array();
    }

    /**
     * Magic getter for getting template vars.
     * @param string $key Name of the var to attempt to get.
     * @return mixed Variable requested or null if not found.
     */
    public function __get($key) {
        if (isset($this->_variables[$key])) {
            return $this->_variables[$key];
        }
        return null;
    }

    /**
     * Set a template variable.
     * @param string $key Variable key.
     * @param mixed $value Variable value.
     */
    public function set($key, $value) {
        $this->_variables[$key] = $value;
    }

    /**
     * Extract template variables and render a template.
     * @param string $template Location of template to render.
     */
    public function render($template) {
        if (is_readable($template)) {
            include($template);
            return true;
        }
        return false;
    }
?>
It can then be used like so:
code:
// Imagine this is in template.php
<p><?php echo $this->some_var; ?></p>
php:
<?
$t = new TemplateRenderer();
$t->set('some_var', 'Hello World!');
$t->render('/path/to/template.php');
?>
Using PHP in the templates is still quite verbose but it's only meant as a quick and simple solution.

DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really

ad homonym posted:

I have a script that reads a file based on the query, and gets a random line from the file:
Instead of running trim() on every single line of the file, you only need to run it on the one random line you pick. Also, if you're only going to have a few set files, I would suggest verifying using an array instead
php:
<?
$validtxt = array('stuff1', 'stuff2', 'stuff3');
$filename = $_GET['q'];
$randomitem = '';

if (in_array($filename, $validtxt)) {
    $items = file($filename.'.txt') or die("File not found, please inform admin");
    $randomitem = trim($items[array_rand($items)]);
} else {
    die("Incorrect filename provided");
}
?>

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

haywire posted:

Though in all fairness this is loving awful and I cant think of a reason to have something like this in well templated PHP.

Indeed, but it doesn't break the forum tables :)

MrMoo
Sep 14, 2000

Pookster posted:

Using PHP in the templates is still quite verbose but it's only meant as a quick and simple solution.
The less verbose version I use, firstly inside a model,
php:
<?
$_ = array('some_var' => 'Hello World!');
include '../templates/my-template.php';
?>
and the template,
code:
<p><?=$_['some_var']?></p>
(edit) to use square brackets.

MrMoo fucked around with this message at 10:40 on Apr 27, 2010

DoctorScurvy
Nov 11, 2005
More of a passing curiosity, really

MrMoo posted:

and the template,
code:
<p><?=$_('some_var')?></p>
Should those be square brackets?

MrMoo
Sep 14, 2000

Probably, mixing up gettext :eng99:

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!
<? ?> (short tags) are not recommended because not all servers support them. This is a configurable option in php.ini and for whatever reason, some servers have this disabled. Also short tags are deprecated in PHP6, so it might be best practice to start coding without using short tags.

gwar3k1
Jan 10, 2005

Someday soon

DarkLotus posted:

<? ?> (short tags) are not recommended because not all servers support them. This is a configurable option in php.ini and for whatever reason, some servers have this disabled. Also short tags are deprecated in PHP6, so it might be best practice to start coding without using short tags.

I haven't looked into templating, but if short tags are removed, how do you output dynamic content without also producing the html on the fly?

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

gwar3k1 posted:

I haven't looked into templating, but if short tags are removed, how do you output dynamic content without also producing the html on the fly?

This:
<?php echo $variable; ?>
Is the same as:
<?=$variable?>

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

gwar3k1 posted:

I haven't looked into templating, but if short tags are removed, how do you output dynamic content without also producing the html on the fly?

immediate answer: <?echo $variable?> and <?= $variable?> are the same when short tags (i.e. <?= ?>) are permissible

short answer: i output dynamic content by using mature libraries that actually do important stuff like sanitization

long answer: holy poo poo, are you serious? is the state of online php tutorials still that loving terrible, or did you stop reading them in 1998?

gwar3k1
Jan 10, 2005

Someday soon
Oh right, so its a case of inline tags are still OK but they should be explicitly doing something not loosely doing it? I didn't know you could use =$var.

And yeah, I stopped reading tutorials when I got the basics of PHP+MySQL down, only using the manual for reference. I've come across templating in the past (mostly questions posed here) and its looked pretty complex for my requirements, but yeah, I should take a look.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

gwar3k1 posted:

Oh right, so its a case of inline tags are still OK but they should be explicitly doing something not loosely doing it? I didn't know you could use =$var.

And yeah, I stopped reading tutorials when I got the basics of PHP+MySQL down, only using the manual for reference. I've come across templating in the past (mostly questions posed here) and its looked pretty complex for my requirements, but yeah, I should take a look.

No, it's a case of quick tags <?= $poop; ?> not being a good practice because A) they are a server by server configuration option and B) they are going away.

spiritual bypass
Feb 19, 2008

Grimey Drawer
It's a fine practice if you're staying with PHP4 because you prefer the stability of older releases :unsmigghh:

Harry Krishna
Jul 2, 2004
I am not your body
I have a main class (Foo) with a member which is set to the name of another class (SingleStatic) which only has one static function (functionA). I want to call that static function from within the bar fucntion

code:
class Foo
{
  private $className;

  public function __construct()
  {
    $this->className = 'SingleStatic';
  }

  public function bar() 
  {
    $b = $this->className;
    $b::functionA();
  }
}

class SingleStatic
{
  static public function functionA()
  {
    return 'this works';
  }
}
Is there a better/easier way to do this than first assigning $className to the variable $b?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Harry Krishna posted:

I have a main class (Foo) with a member which is set to the name of another class (SingleStatic) which only has one static function (functionA). I want to call that static function from within the bar fucntion

code:
class Foo
{
  private $className;

  public function __construct()
  {
    $this->className = 'SingleStatic';
  }

  public function bar() 
  {
    $b = $this->className;
    $b::functionA();
  }
}

class SingleStatic
{
  static public function functionA()
  {
    return 'this works';
  }
}
Is there a better/easier way to do this than first assigning $className to the variable $b?

What's wrong with:
php:
<?
class Sta{
 static public function funcA()
 {
  echo "OOOOH!";
 }
}

class Stb{
 public function bar()
 {
  Sta::funcA();
 }
}
$pie = new Stb();
$pie->bar();
?>
EDIT: I'm guessing that you are actually asking this because you want to dynamically set the class that has it's static method called... you can do something like this then:

php:
<?
class Sta{
 static public function funcA()
 {
  echo "OOOOH!";
 }
}

class Stb{
 private $className;
 private $methodName = 'funcA';

 function __construct( $n )
 {
   $this->className = $n;
 } 

 public function bar()
 {
  //call_user_func( $this->className . '::' . $this->methodName ); // works in 5.3.x and up
  call_user_func( array( $this->className , $this->methodName ) );

 }
}

$pie = new Stb( 'Sta' );
$pie->bar();
?>

Lumpy fucked around with this message at 15:37 on Apr 29, 2010

hasegawa
Dec 30, 2008

Wedge Regret
Ok, we're slogging through our big project thing...The idea is that the user can get usage statistics for the campus online course platform. And by usage statistics, we mean SELECT COUNT(*) type statistics...basically the number of hits in our log database.

So the user (using drop down boxes) specifies the semester, and then a college, department, and course followed by a "tool view"...In this example, this is all defined at the bottom via the $userselected(blank) variable. If you notice, all that is selected is term and tool...we're trying to craft the code for different queries based on the scenario. Say that didn't specify a college/department/course...that means the user just wants overall stats for a tool's usage in a semester.


OK, now onto the problem(s)...we've got this set to loop through some arrays. Look at $counter...it always returns "0" when we echo it. Same for the following department and college counters...

Any ideas as to what we're doing wrong?


EDIT: I chopped down the "userselected" var names because I'm kind of breaking tables...if you see any discrepancies in the $user variables, it's not like that in our regular code
EDIT2: Also, disregard the print_r stuff...just trying to see what's going on behind the scenes


EDIT3: First half of code removed, see post towards bottom of page for full code

hasegawa fucked around with this message at 20:08 on Apr 30, 2010

Yay
Aug 4, 2007
At a guess, I'd say its always 0 because collegeCount() always returns in the first iteration of the while loop?

SiCk
Jul 4, 2003

My name's SiCk, and I'm the Biggest Idiot Ever!

Yay posted:

At a guess, I'd say its always 0 because collegeCount() always returns in the first iteration of the while loop?

Surely it'd return the last? - It'll re-write $counter every single time, because it's not being appended, it's being declared.

There's probably more issues in there, but just from what you said, surely something like this would solve it?
php:
<?php
$counter 0;
while($allCollegeArray mysql_fetch_array($allCollegeQueryMYSQL_ASSOC))
{
  $add collegeCount($allCollegeArray['college_id'], $usrSelDept$usrSelCourse$usrSelTerm$usrSelTool);     
  $counter+$add;
}
echo $counter;
?>

Or something of that nature..

(Not saying any of that code will actually work, but pseudo-wise, that'd solve that part of the issue?)

SiCk fucked around with this message at 11:04 on Apr 30, 2010

hasegawa
Dec 30, 2008

Wedge Regret
hmm...I just tried those recommendations (moving the $counter variable before the while statement, echoing it after the while statement) but it's still just returning a list of zeros alongside the list of increasing values from the array. So that means that the looping statement is working, but the counter isn't.

And the SQL works, I can run it in PHPmyadmin and get plenty of hits as a result...not sure what's going on.

Still, thanks for the help thus far.


EDIT: If you set $counter=2, and then
echo $counter;
echo "<br />";
echo $add;
You'll get

02
0

As output. The array stuff comes form the dept loop, but I'm guessing "02" is $counter and "0" is $add. I guess that means that it isn't calling the collegeCount() function correctly?

hasegawa fucked around with this message at 16:21 on Apr 30, 2010

Pissflaps
Oct 20, 2002

by VideoGames
Is there a pre-made php script that, given a mysql table, will show it in an access-style table, where it picks up on the fields names and allows you to sort and filter, like you could do in an access table view or excel spreadsheet?

epswing
Nov 4, 2003

Soiled Meat
What you're looking for is called a "scaffolding".

SiCk
Jul 4, 2003

My name's SiCk, and I'm the Biggest Idiot Ever!

hasegawa posted:

hmm...I just tried those recommendations (moving the $counter variable before the while statement, echoing it after the while statement) but it's still just returning a list of zeros alongside the list of increasing values from the array. So that means that the looping statement is working, but the counter isn't.

And the SQL works, I can run it in PHPmyadmin and get plenty of hits as a result...not sure what's going on.

Still, thanks for the help thus far.


EDIT: If you set $counter=2, and then
echo $counter;
echo "<br />";
echo $add;
You'll get

02
0

As output. The array stuff comes form the dept loop, but I'm guessing "02" is $counter and "0" is $add. I guess that means that it isn't calling the collegeCount() function correctly?

Just noticed you have the same issue in your while statement within the collegecounter() as i pointed out in your first function.. ( again i'm not great with php, so bear with me if this is wrong.. i'm sure someone will correct me if i'm being a tard )

try this? - I'm not wholly sure you can add variable to variable like '$one+$four', but i dont see why you couldnt, providing they're both integers.

php:
<?php

    $collegeCounter 0;
    while($collegeArray mysql_fetch_array($collegeQueryMYSQL_ASSOC))
    {
        echo "<br />\n";
        print_r($collegeArray);
        echo "<br />\n";
        $toolSQL "SELECT tool_identifier FROM tooltable WHERE tooltable.tool_id = '" $userSelectedTool "'";
        $ToolString mysql_query($toolSQL);                            
        $deptCounter += deptCount2($usrSelClg$collegeArray['dept_id'], $usrSelCourse$usrSelTerm$usrSelTool);
        echo $deptCounter;
        $collegeCounter += $deptCounter;        
    }
    return $collegeCounter;

?>

You were returning $collegeCounter every time that while was run, you need to append to it, and not return it a few times. This is all dependant on whether or not that 'deptCount2()' function is working too..


edit: looked it up, there is no reason why you cant do $this+that, but it's supposed to be $this += $that.. but you already knew that, you had it already. I've learned something today! hoorah!

SiCk fucked around with this message at 17:00 on Apr 30, 2010

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

SiCk posted:

You were returning $collegeCounter every time that while was run, you need to append to it, and not return it a few times. This is all dependant on whether or not that 'deptCount2()' function is working too..

This is mainly for the guy who started all this, but a function can't "return multiple times" Once you hit a return, your function stops executing.


php:
<?
function poop()
{
  for( $i = 0; $i < 100000; $i++ )
  { 
    echo "$i";
    return $i;
  }
}

function blah()
{
  while( TRUE )
  {
    echo "lol";
    return 'snacks';
  }
}

poop(); 
blah();
?>
Will print "1" and "lol" once. Both loops and functions exit as soon as the return happens.

hasegawa, it seems that the function you don't show us is probably doing something equally as bad as the code you have shown us, so I'd look there.

SiCk
Jul 4, 2003

My name's SiCk, and I'm the Biggest Idiot Ever!
That makes sense.. cheers, good to know :)

hasegawa
Dec 30, 2008

Wedge Regret

Lumpy posted:

hasegawa, it seems that the function you don't show us is probably doing something equally as bad as the code you have shown us, so I'd look there.

Ok, here's the entire thing..I'll edit the code out of my first post so that you don't have to scroll twice as long to get here.

PS: Sorry for more table breakage

php:
<?php
$con mysql_connect("localhost""name""pass");
    if(!$con) {die("could not connect to MYSQL");}
    mysql_select_db("db1"$con);

function selectProperArrayType($usrSelClg$usrSelDept$usrSelCourse$usrSelTerm$usrSelTool)
{
    if ($usrSelClg == "" && $usrSelDept == "" && $usrSelCourse == "")
    {
        $allCollegeSQL "SELECT college_id, name FROM collegetable ORDER BY name";
        $allCollegeQuery mysql_query($allCollegeSQL);
        $counter 2;    
        while($allCollegeArray mysql_fetch_array($allCollegeQueryMYSQL_ASSOC))
        {
            $add collegeCount($allCollegeArray['college_id'], $usrSelDept$usrSelCourse$usrSelTerm$usrSelTool);
            $counter+=$add;
                
        }
    echo $counter;
    echo "<br />";
    echo $add;
    }
    else
    {
    echo "problem";
    }
    
}
function collegeCount($usrSelClg$usrSelDept$usrSelCourse$usrSelTerm$usrSelTool)
{
    $collegeSQL "SELECT dept_id, dept_name
                    FROM db1.depttable
                    LEFT JOIN db1.collegetable
                    ON db1.depttable.college = db1.collegetable.college_id
                    WHERE college_id = '" $usrSelClg "'
                    ORDER BY dept_name ASC";
    echo $collegeSQL;
    echo "<br />\n";
    
        
    $collegeQuery mysql_query($collegeSQL);
    while($collegeArray mysql_fetch_array($collegeQueryMYSQL_ASSOC))
    {
        echo "<br />\n";
        //print_r($collegeArray);
        echo "<br />\n";
        $toolSQL "SELECT tool_identifier FROM db1.db1_tools WHERE db1.db1_tools.tool_id = '" $usrSelTool "'";
        $ToolString mysql_query($toolSQL);                            
        $deptCounter += deptCount2($usrSelClg$collegeArray['dept_id'], $usrSelCourse$usrSelTerm$usrSelTool);
        echo $deptCounter;
        //$collegeCounter = $deptCounter;        
        //return $collegeCounter;
        $collegeCounter += $deptCounter;    
    }
    return $collegeCounter;
}

function deptCount2($usrSelClg$usrSelDept$usrSelCourse$usrSelTerm$usrSelTool)
{
    $deptSQL "SELECT id, longtitle 
        FROM proddb.coursetble 
        LEFT JOIN db1.depttable 
        ON db1.depttable.dept_name = proddb.coursetble.depttitle 
        WHERE db1.depttable.dept_id = '" $usrSelDept "'
        AND proddb.coursetble.term = '" $usrSelTerm "'
        ORDER BY longtitle DESC            
        ";
    
    $deptQuery mysql_query($deptSQL);
        
    while($deptArray mysql_fetch_array($deptQueryMYSQL_ASSOC))
    {            
        
        echo "<br />\n";
        print_r($deptArray);
        echo "<br />\n";
        $toolSQL "SELECT tool_identifier FROM db1.db1_tools WHERE db1.db1_tools.tool_id = '" $usrSelTool "'";        
        $ToolString mysql_query($toolSQL);
        $usageQuantity getQuantity($deptArray['id'], $ToolString);    
        return $usageQuantity;        
    }
}
function getQuantity($usrSelCourse$ToolString)
{
    $ToolArray mysql_fetch_array($ToolStringMYSQL_ASSOC);    
    $sql "SELECT
            count(*) as Quantity
        FROM
            db1.apache_log
        LEFT JOIN
            proddb.courseadmin
            ON proddb.courseadmin.id = db1.apache_log.log_id_param
        LEFT JOIN
            proddb.enroll_table
            ON proddb.enroll_table.coursesourcedid = proddb.courseadmin.idnumber
        LEFT JOIN
            proddb.people
            ON proddb.people.username = db1.apache_log.log_user
        LEFT JOIN
            proddb.coursetble
            ON proddb.coursetble.sourcedid = proddb.courseadmin.idnumber
        WHERE
            db1.apache_log.log_request = '" $ToolArray['tool_identifier'] . "' AND
            proddb.enroll_table.personsourcedid = proddb.people.sourcedid AND
            proddb.enroll_table.role = 1 AND
            proddb.coursetble.id = '" $usrSelCourse ."'";
    $result mysql_query($sql);
    $row mysql_fetch_array($resultMYSQL_ASSOC);
    return $row['Quantity'];
}


?>

<!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" />
<title>Untitled Document</title>
</head>

<body>

<?php

$usrSelTerm "201010";
$usrSelClg "";
$usrSelDept "";
$usrSelCourse "";
$usrSelTool "6";

selectProperArrayType($usrSelClg$usrSelDept$usrSelCourse$usrSelTerm$usrSelTool);


?>
</body>
</html>        

hasegawa fucked around with this message at 20:50 on Apr 30, 2010

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

hasegawa posted:

Ok, here's the entire thing..I'll edit the code out of my first post so that you don't have to scroll twice as long to get here.

PS: Sorry for more table breakage


php:
<?
function deptCount2($usrSelClg, $usrSelDept, $usrSelCourse, $usrSelTerm, $usrSelTool)
{
   // STUFF SNIPPED
        
    while($deptArray = mysql_fetch_array($deptQuery, MYSQL_ASSOC))
    {            
        
        echo "<br />\n";
        print_r($deptArray);
        echo "<br />\n";
        $toolSQL = "SELECT tool_identifier ... ";        
        $ToolString = mysql_query($toolSQL);
        $usageQuantity = getQuantity($deptArray['id'], $ToolString);   
//////////// RETURN IN A WHILE LOOP ///////////// 
        return $usageQuantity;        
//////////////////////////////////////////////////
    }
}
?>
Your function does not do what you think it does.

hasegawa
Dec 30, 2008

Wedge Regret

Lumpy posted:

php:
<?
function deptCount2($usrSelClg, $usrSelDept, $usrSelCourse, $usrSelTerm, $usrSelTool)
{
   // STUFF SNIPPED
        
    while($deptArray = mysql_fetch_array($deptQuery, MYSQL_ASSOC))
    {            
        
        echo "<br />\n";
        print_r($deptArray);
        echo "<br />\n";
        $toolSQL = "SELECT tool_identifier ... ";        
        $ToolString = mysql_query($toolSQL);
        $usageQuantity = getQuantity($deptArray['id'], $ToolString);   
//////////// RETURN IN A WHILE LOOP ///////////// 
        return $usageQuantity;        
//////////////////////////////////////////////////
    }
}
?>
Your function does not do what you think it does.
Ok, I just bumped "return $usageQuantity;" to the next curly brace (outside of the while loop)...and this time, it did this:

quote:

Array ( [dept_id] => 2 [dept_name] => Anthropology )
0
Array ( [dept_id] => 4 [dept_name] => Biology )
0
Array ( [dept_id] => 7 [dept_name] => Chemistry )
0
//ETC.....

Fatal error: Maximum execution time of 60 seconds exceeded in E:\xampp\htdocs\results2.php on line 109


Time out...is it some sort of infinite while loop we've invoked?

EDIT: Ok...my group member just revealed to me that the code I've been using is "Results2". He created it because results1 wouldn't do the colleges properly. Upon playing with results1 (and pulling the "return"s out of the while loops), it sort of works.

quote:

Accounting: 0
Business: 2
Computer and Information Syst: 0
Economics: 2
Finance Banking and Insurance: 2
Management: 0
Marketing: 2

I created 3 people for a class in each department of that college....1 teacher and 2 students per class. Since the code specifies that the role=student, that's why we're seeing 2. So it (sort of) works. And if I set a department, it will list out all of the courses within that department and the class that I created students for will also say 2. That's good. But, when we try to do it for all colleges, it does this:

quote:

0
0
0

0
0

Fatal error: Maximum execution time of 60 seconds exceeded in E:\xampp\htdocs\results.php on line 39
...which is basically what results2 was doing, which is why I think my teammate made results2 (to isolate the problem...or make it 10x worse). Gimme a minute, I'll change the code.

EDIT2: Ok...he's getting better results by using global variables. I think we are kinda making progress so for now I'll say "Thanks for the help it (kinda) got us back on track".

hasegawa fucked around with this message at 21:30 on Apr 30, 2010

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


Pissflaps posted:

Is there a pre-made php script that, given a mysql table, will show it in an access-style table, where it picks up on the fields names and allows you to sort and filter, like you could do in an access table view or excel spreadsheet?

phpMyAdmin

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

hasegawa posted:

Ok, I just bumped "return $usageQuantity;" to the next curly brace (outside of the while loop)...and this time, it did this:



Time out...is it some sort of infinite while loop we've invoked?

The web server has a limit on how long a PHP script can execute so scripts that *do* run infinite loops can't hog all the resources of the server. Your server's time limit per script appears to be 60 seconds, and your script is taking longer than that to run.

Adbot
ADBOT LOVES YOU

Hootie Hoo
Nov 13, 2008

by angerbot
Ok, so I got this wordpress blog theme (simplr) that I'm trying to customize a little. Right now it's got this poo poo at the bottom:


and I want to get rid of everything there except for the archives box. The .php file that contains this section is sidebar.php, and is here:
http://pastebin.com/wsB1hzct

I tried my own cack-handed editing and it just resulted in a php error. I'm stupid and unsure of what to delete and what to leave. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply