A database for my data

From: ANT_THOMAS10 Feb 2009 00:25
To: ALL93 of 158
Ok, it's working now, seems it was my id issue. Yay, done.
From: Peter (BOUGHTONP)10 Feb 2009 00:27
To: ANT_THOMAS 94 of 158
You probably want something like:
code:
if ( ! isNumeric($id) ){ throwError('Invalid id supplied'); }


Just before the query.

That way, next time you have null/blank/other in Id you don't get an apparent success whilst nothing actually happens... :)
From: ANT_THOMAS10 Feb 2009 01:43
To: ALL95 of 158

Since it's all to do with the same database/site I'll ask it in this thread.

 

Is it possible to have a link/button on a website that tells the server to execute a batch file of some sort?

 

For my site I use Irfanview to convert PDFs to PNGs which are dumped in a certain folder, and I do this manually. After looking around it seems that you can run Irfanview from the command line with whatever switches you want, I'll have to look into what exactly I need, but only if it's worth doing.

From: Drew (X3N0PH0N)10 Feb 2009 02:16
To: ANT_THOMAS 96 of 158
http://uk2.php.net/manual/en/function.exec.php

Not sure it whether works on windows.
From: THERE IS NO GOD BUT (RENDLE)10 Feb 2009 18:52
To: ANT_THOMAS 97 of 158
If you're wanting to do image conversion, take a look at ImageMagick, for which there is a PHP PECL package.
From: ANT_THOMAS16 Feb 2009 22:16
To: THERE IS NO GOD BUT (RENDLE) 98 of 158
I shall take a look at that some point soon!
From: ANT_THOMAS16 Feb 2009 22:35
To: ALL99 of 158
Right, I have this code:

PHP code:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ $prefixweb = "./nmr/{$row['machine']}/{$row['year']}/{$row['month']}/data/AB/nmr/{$row['servercode']}/";
    $prefixuni = "file:///N:/vol3/users/snmrdata/{$row['machine']}/{$row['year']}/{$row['month']}/data/AB/nmr/{$row['servercode']}/";
 
    echo " STUFF ";
}


I want to make it so when "machine" ({$row['machine']}) is a certain specific value, the value being "varian", the directory structures of $prefixweb and $prefixuni change.

If I'm thinking right I need to use an if else statement.

I've tried and failed as usual, hence the post.

I've concentrated on only one of the directory structures, $prefixuni, since that's the one I use the most.

So yeah, I've got this:

PHP code:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{$prefixweb = "./nmr/{$row['machine']}/{$row['year']}/{$row['month']}/data/AB/nmr/{$row['servercode']}/";
 
if ($row['machine']=="varian")
{ 
$prefixuni = "file:///N:/vol3/users/snmrdata/{$row['year']}/service/{$row['month']}/4_StuYEAR/{$row['servercode']}/"
 
else 
 
$prefixuni = "file:///N:/vol3/users/snmrdata/{$row['machine']}/{$row['year']}/{$row['month']}/data/AB/nmr/{$row['servercode']}";
}
    echo " STUFF ";
}


It don't work, why? :C


Also, can you have it try for a few different specifics then to go to a default?

As in

If A then 1 or
if B then 2 or
if C then 3
else 4
From: steve16 Feb 2009 22:48
To: ANT_THOMAS 100 of 158
if (uh) {
something
}
else
{
something else
}

You have missed the closing }'s. Although that might not be the problem, as you've not mentioned the very obvious error that would come with that?

That might not even be PHP. I am late to thi thread. :C
From: ANT_THOMAS16 Feb 2009 22:55
To: steve 101 of 158
code:
Parse error: syntax error, unexpected T_ELSE in C:\wamp\www\full-iftest.php on line 41


After adding a } it still doesn't like it. Clearly has an issue with the else statement.
From: dave (10_ROGUE)16 Feb 2009 23:01
To: ANT_THOMAS 102 of 158

What about the missing { before the else?

 

and by before I do ofcourse mean after.

EDITED: 16 Feb 2009 23:02 by 10_ROGUE
From: empathy16 Feb 2009 23:47
To: ANT_THOMAS 103 of 158
missing semicolon?
From: ANT_THOMAS17 Feb 2009 00:08
To: empathy 104 of 158
Possibly that! It works now :)
From: ANT_THOMAS23 Mar 2009 22:41
To: ALL105 of 158

Yay, another question, and most likely an easy one to answer. I am trying to make my thingy easier to make changes to in the future and because I am currently doing things in a retarded manner I want to change things.

 

I currently have a few separate pages/files to show entries in certain ways

 

full.php - standard single entry based on id
full5.php - as above but 5 entries
fullc.php - pulls single entry based on code
fullr.php - pulls single entry based on lab book ref

 

I realise this is very much the wrong way to do things, hence why I want to change it.

 

I currently decide things things based on using $_GET

 

.....php?id=xxx
.....php?code=ATxxx
.....php?ref=ATrxxx

 

I have easily got rid of the one to pull 5 entries so that's not a problem. I want to now combine all the others so I can for example use any of these:

 

full.php?id=xxx
full.php?code=ATxxx
full.php?ref=ATrxxx

 

I use these to get the values:

 

$tableid = $_GET['id'];
$tablecode = $_GET['code'];
$ref = $_GET['ref'];

 

But how do I now tell it to fetch the record based on which is actually present?

 

There will only ever be one of those there at any one time. I assume using some sort of if else null statements would sort it but I'm not sure how to go about it.

From: ANT_THOMAS24 Mar 2009 00:25
To: ALL106 of 158
Right, I think I may be somewhere along the right lines but it doesn't work...

I have :

PHP code:
 
$get = $_GET['get'];
 
if $get == ('AT###')
{$query  = "SELECT * FROM nmr WHERE code = $ref LIMIT $ent ";}
 
else if $get == ("ATr###")
{$query = "SELECT * FROM nmr WHERE labbookref = $ref ";}
 
else $get == ("###") 
{$query = "SELECT * FROM nmr WHERE id >= $ref LIMIT $ent ";}
 


$ent is just the number of entries to fetch.

$get is either going to be either of these

AT### - (code)
ATr### - (labbookref)
### - (id)

How? :C
From: Peter (BOUGHTONP)24 Mar 2009 01:09
To: ANT_THOMAS 107 of 158
You can use a regular expression to identify things.


Not sure if this is exactly right PHP syntax, but something along these lines should work...

php code:
preg_match ( /^(ATr?)?(.*)$/ , $get , $groups );
 
$ref= $groups[2];
 
$query = "SELECT * FROM nmr ";
 
switch( $groups[1] )
{
 
	case 'AT':
		$query .= "WHERE code = $ref";
	break;
 
	case 'ATr':
		$query .= "WHERE labbookref = $ref";	
	break;
 
	default:
		$query .= "WHERE id >= $ref";
	break;
}
 
$query .= "LIMIT $ent";
 
EDITED: 24 Mar 2009 01:11 by BOUGHTONP
From: ANT_THOMAS24 Mar 2009 01:27
To: Peter (BOUGHTONP) 108 of 158
Thank you for the reply.

I've managed to get it to work using what is probably an unorthadox way but it works :D


PHP code:
$get = $_GET['get'];
$ent= $_GET['ent']+1;
$grab = $_GET['grab'];
 
 
if ($get == "a")
{$query = "SELECT * FROM nmr WHERE id >= '$grab' LIMIT $ent ";}
 
if ($get == "b")
{$query  = "SELECT * FROM nmr WHERE code = '$grab' LIMIT $ent ";}
 
if ($get == "c")
{$query = "SELECT * FROM nmr WHERE labbookref = '$grab' ";}


Using a link along the lines of:

http://server/full.php?get=a&grab=25&ent=5
From: Monsoir (PILOTDAN)24 Mar 2009 10:43
To: ANT_THOMAS 109 of 158
Beware of putting input directly into SQL queries.
From: koswix24 Mar 2009 15:39
To: ALL110 of 158
*spooky music & lightning*
From: ANT_THOMAS 3 Aug 2010 18:29
To: ALL111 of 158
Yay, more of me coding and being shit at it.

Simple one (I think)

I have a database with this table..

date day month year dayofweek weight
2010-08-03 03 August 2010 Tuesday 82.5


And that's an example of the data within it.

All I want to do is to be able to select certain rows based on month and year, or year

Eg..
Everything from August 2010
Everything from 2010

I'm guessing using WHERE is the way to go and currently I'm going for it using the URL and grabing the variable from there but I have an issue.

Using...
PHP code:
$month = $_GET['month'];
$year = $_GET['year'];

PHP code:
$sql="SELECT * FROM weight WHERE month='$month' & year='$year' OR year='$year'";

Eg :

1) http://server/page.php?year=2010 - Gives everything from 2010

2) http://server/page.php?month=August&year=2010 - Gives everything from 2010 and not August 2010

I can kinda see why it's happening but don't know how to sort it :C
From: Drew (X3N0PH0N) 3 Aug 2010 18:36
To: ANT_THOMAS 112 of 158

You'll need to check whether month is set and if so use the month & year query and if not just query on the year.

 

I don't think it's reasonably doable in a single statement.

 

i.e.

 

if ($month != "") {
$sql="SELECT * FROM weight WHERE month='$month' & year='$year';
} else {
$sql="SELECT * FROM weight WHERE year='$year'";
}

 

(although someone may well have a cleverer solution)

EDITED: 3 Aug 2010 18:36 by X3N0PH0N