Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | ebay bidding

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > Internet Discussion
Register FAQ Community Calendar

PHP help needed this time :D
Reply
 
Thread Tools
Old 19-03-2004, 09:12   #1
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
PHP help needed this time :D

hellup, I need to include a CSS file based on a field entry in a database

Let's say the field name is test, it has 3 entries, nob, blah and oi

What I need to to do is enter the url (for example) http://www.website.com/test.php?test=oi and it'll then read the database, see that the field test is "oi" and load a relevant CSS file for "oi" ...

does that make any sense?

Cheers

edit: alternatively, what'd be easier for me to incorporate is if someone goes to http://www.website.com/test.php?test=oi it'll load oi.css and bypass the database automatically.
Bifta is offline   Reply With Quote
Advertisement
Old 19-03-2004, 09:35   #2
Jon M
Inactive
 
Jon M's Avatar
 
Join Date: Oct 2003
Location: East Midlands
Age: 48
Services: Rural BB - Radio Link via Virgin Fibre
Posts: 2,947
Jon M has a bronze arrayJon M has a bronze arrayJon M has a bronze array
Jon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze array
Send a message via MSN to Jon M
Re: PHP help needed this time :D

i've done this with cookies in the past.. it's fairly straight forward.. and avoids the need to have complicated things like user accounts
Jon M is offline   Reply With Quote
Old 19-03-2004, 09:37   #3
Jon M
Inactive
 
Jon M's Avatar
 
Join Date: Oct 2003
Location: East Midlands
Age: 48
Services: Rural BB - Radio Link via Virgin Fibre
Posts: 2,947
Jon M has a bronze arrayJon M has a bronze arrayJon M has a bronze array
Jon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze arrayJon M has a bronze array
Send a message via MSN to Jon M
Re: PHP help needed this time :D

like this : http://www.codepoetry.net/archives/2...e_with_php.php
Jon M is offline   Reply With Quote
Old 19-03-2004, 10:13   #4
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP help needed this time :D

Cheers, but that wouldn't work for what I'm doing basically let's say there's 100 customers, each uses a different stylesheet, we incorporate the page into their site so what I need to do is read the URL for determine the stylesheet, probably didn't explain it very well, still hungover. Let's say the URL is www.wherever.com/index.php?css=customer1

I want it to then incorporate "customer1.css" (which'll be uploaded manually).
Bifta is offline   Reply With Quote
Old 19-03-2004, 11:16   #5
Peter
Inactive
 
Peter's Avatar
 
Join Date: Jun 2003
Location: Lincoln, UK
Posts: 44
Peter is an unknown quantity at this point
Re: PHP help needed this time :D

This will work if you don't want it to save the selection over different sessions.

PHP Code:
if (!$css) $css="default";
switch(
$css){

// Set default css file if none is selected in the URL.
case "default":
$css = default.css;
break;

//Modify below for each css choice.

case "css1":
if (@
join ('', file ("customer1.css"))=="")
$css = default.css;
else 
$css = customer1.css
break;

// Don't modify below except to set your default css file.

default:
include(
"default.css");
break; } 
Then for the HTML part, if it's not within PHP tags, simple use

PHP Code:
<link href="<? echo $css;?>" rel="stylesheet" type="text/css">
Else, if it is...

PHP Code:
echo "<link href='$css' rel=\"stylesheet\" type=\"text/css\">" 
Peter is offline   Reply With Quote
Old 19-03-2004, 11:22   #6
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP help needed this time :D

Ah now see, I fixed it just before you posted that

I just stuck in

Code:
<?php

print "<link rel=\"stylesheet\" type=\"text/css\" href=$css.css>";
?>
and it does the job perfectly, I then just use a url like http://www.blah.com/css=whatever
Bifta is offline   Reply With Quote
Old 19-03-2004, 11:24   #7
Peter
Inactive
 
Peter's Avatar
 
Join Date: Jun 2003
Location: Lincoln, UK
Posts: 44
Peter is an unknown quantity at this point
Re: PHP help needed this time :D

Yup, that works equally well.
Peter is offline   Reply With Quote
Old 19-03-2004, 11:30   #8
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP help needed this time :D

Quote:
Originally Posted by Peter
Yup, that works equally well.
Ah haha .. see, it's a search page for a database .. the search page creates a URL string like results.php?something=arse&somethingelse=arsetoo

need to carry the CSS details over, I populated a hidden field called "styles" with the relevant value and it carries that over in the URL but the results page doesn't know wtf "styles" is and gives me all sorts of errors, pretty sure I have to create a variable on the results page to tell the script that "styles" is something or other .. but I've no idea what
Bifta is offline   Reply With Quote
Old 19-03-2004, 13:20   #9
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: PHP help needed this time :D

Quote:
Originally Posted by Bifta
Ah haha .. see, it's a search page for a database .. the search page creates a URL string like results.php?something=arse&somethingelse=arsetoo

need to carry the CSS details over, I populated a hidden field called "styles" with the relevant value and it carries that over in the URL but the results page doesn't know wtf "styles" is and gives me all sorts of errors, pretty sure I have to create a variable on the results page to tell the script that "styles" is something or other .. but I've no idea what
If you basically need to get a variable from the URL just do it like this:

PHP Code:
$styles = $_GET['styles'];
echo 
"<link rel=\"stylesheet\" href=\"$styles\" type=\"text/css\" />"; 
Richard M is offline   Reply With Quote
Old 19-03-2004, 13:30   #10
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP help needed this time :D

Quote:
Originally Posted by Richard M
If you basically need to get a variable from the URL just do it like this:

PHP Code:
$styles = $_GET['styles'];
echo 
"<link rel=\"stylesheet\" href=\"$styles\" type=\"text/css\" />"; 
Still gives me this error

Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in xxxxxxxxxxxxxxxxxxxxxxxx
because styles=whatever is in the URL it's somehow trying to find that field in the DB by the look of it, when it can't find it it throws the above
Bifta is offline   Reply With Quote
Old 19-03-2004, 13:48   #11
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: PHP help needed this time :D

Quote:
Originally Posted by Bifta
Still gives me this error

Code:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in xxxxxxxxxxxxxxxxxxxxxxxx
because styles=whatever is in the URL it's somehow trying to find that field in the DB by the look of it, when it can't find it it throws the above
I'm just guessing here but you'd need something like this:

PHP Code:
// Open SQL connection.

if (!$dbconnection) {
  echo( 
"<p>Unable to connect to the " .
        
"database server at this time.</p>" );
  exit();
}

// Select DB

@mysql_select_db($dbname) or die("Could not select database");

// The query for getting the $style

$result = @mysql_query("SELECT * FROM " . $table_name . " WHERE styles='" . $styles . "'");
if (!
$result) {
  echo(
"<p>Error performing query: " .
       
mysql_error() . "</p>");
  exit();
}

// Loop through the array and echo out the $style retrieved from the DB

while ( $row = @mysql_fetch_array($result) ) {
$styles = $row['styles'];
echo 
"<link rel=\"stylesheet\" href=\"$styles\" type=\"text/css\" />"; 
}

// Close SQL connection.

mysql_close($dbconnection); 
You could also use the more OOP way by using mysql_fetch_object() instead like so:

PHP Code:
// Open SQL connection.

if (!$dbconnection) {
  echo( 
"<p>Unable to connect to the " .
        
"database server at this time.</p>" );
  exit();
}

// Select DB

@mysql_select_db($dbname) or die("Could not select database");

// The query for getting the $style

$result = @mysql_query("SELECT * FROM " . $table_name . " WHERE styles='" . $styles . "'");
if (!
$result) {
  echo(
"<p>Error performing query: " .
       
mysql_error() . "</p>");
  exit();
}

// Get the object from the DB and echo out the $style.

$style_object = @mysql_fetch_object($result);
$styles = $style_object->styles;
echo 
"<link rel=\"stylesheet\" href=\"$styles\" type=\"text/css\" />"; 

// Close SQL connection.

mysql_close($dbconnection); 
Richard M is offline   Reply With Quote
Old 19-03-2004, 14:12   #12
Bifta
Inactive
 
Join Date: Jul 2003
Location: Eglinton, Co. Derry
Posts: 7,640
Bifta has a nice shiny starBifta has a nice shiny star
Bifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny starBifta has a nice shiny star
Re: PHP help needed this time :D

eep .. ok, I'm going to attempt to fit that around my code, cheers for the help
Bifta is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:44.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum