Jump to content

[resolved] using a URL (string) as a primary key


countrybumpkin

Recommended Posts

Hey all

I'm new to this php and MySQL stuff. My script needs to be able to find out what the HTTP_HOST is (easy) and then look that up in a table to find a corresponding Client ID (because clients will have multiple URLS to get to their sites).

I'm using

[code]('SELECT clientID FROM domains WHERE domain = '.$SERVER_["HTTP_HOST"]);[/code]

but, of course, the WHERE part has to be a unique identifier. For some reason I can't work out how to make fields that contain URLs into a primary key.

Any ideas? I'm sure this has been done before :S
Link to comment
Share on other sites

Sorry! Concise language was never my strong point.

I'm building a CMS which will run many (small) sites from one database. The system needs to check what URL the user has landed at in order to display the correct information on the page.

Say, the user pulls up www.aclient.com/viewArticle.php?ID=3, my script should then put the www.aclient.com part into a query on the database in order to establish what the CLIENT ID is, and then go ahead and display the right information for that client.

So, I have a table in the database called "domains", which lists each DOMAIN against a CLIENTID, because each client could have a few domains that they want to point to the system.

Do you follow? :-S hope that made sense........ I'm rapidly losing the ability to think right!

Hope you can help
Link to comment
Share on other sites

[quote]
Say, the user pulls up www.aclient.com/viewArticle.php?ID=3, my script should then put the www.aclient.com part into a query on the database in order to establish what the CLIENT ID is, and then go ahead and display the right information for that client.
[/quote]
What i'm getting is that you want the page to display differently based on what ID is and to do that you use $_GET[id] and if ithe URL is www.mysite.com/view.php?id=3 then $_GET[id] would be equal three.

I'm sorry if this answers your question, but i'm not sure exactly what you're asking.
Link to comment
Share on other sites

Ok, that sounds good. I'll try what you suggest!

I think my problem is on the mySQL side. Doesn't the WHERE part of the statement have to be a unique/primary key field? Or am I just dreaming that...

Oh, and in my example, the ID=3 is the ID of the article to display, which could be a sydicated piece of content across multiple clients. I am re-branding content based on the URL. So the ID=3 is the article number, not the client number, or else GET would have been a very good idea!

Cheers for all your suggestions.

Ben
Link to comment
Share on other sites

[quote author=countrybumpkin link=topic=114077.msg464008#msg464008 date=1162861681]
Oh, and in my example, the ID=3 is the ID of the article to display, which could be a sydicated piece of content across multiple clients. I am re-branding content based on the URL. So the ID=3 is the article number, not the client number, or else GET would have been a very good idea!
[/quote]
It could be used as an article number.
Link to comment
Share on other sites


Right - have tried your suggestions, but sadly to no avail. The error I keep getting is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /content/.........../includes/DbConnector.php on line 50

Here's the offending code:

[code]//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
return mysql_fetch_array($result);
}[/code]
Link to comment
Share on other sites

That isn't the offending code. More than likely your query is failing and therefore $result is not a mysql resource. Post the code around your call to mysql_query(), and make sure your checking it actually worked before trying to use it. eg;

[code=php:0]
if ($result = mysql_query($sql)) {
  // $result holds a connection resource.
} else {
  // Something failed.
  echo mysql_error();
}
[/code]
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.