These are smarty template files. (smarty.net). Iirc I put smarty in the zipfile.

The one other thing it needs is a database, which I put in test.sql
You will need to change the username and password in the mysqlConnect function in includes/functions.inc.php

If there is anything else, just let me know.

Where is test.sql? I cannot find it.

I changed the username and password to the one I use for my database but I'm not sure if thats correct. Even if I did find the test.sql how does it connect to that? I've only ever connected to the database on CPanel, I've never done it from a file on my own computer.

Look back in this thread, there's a link to it.

It's an sql file you need to execute to create the tables you need for the example.

If you've created the tables on your server and you uploaded my test files, it should run.

Yea it still just brings me to my host page telling me that wowtah.com has been registered.

The way I am trying to test it is having a random link on my site that just goes to 'index.php' thats ok right?

Yes. That should be all.

Ok. Well, I been fustrated with all this I haven't even felt like working on my website lol. But I am calmed down and back for more. Thing is though, I wanna give up on trying to get that PhP you gave me to work and instead ask if perhaps there is another way I can learn how to do what I want.

To refresh. What I want to do is use php to I guess generate a page for my database data to go on depending on what link is clicked on. Remember my example website was http://www.wowhead.com, and the page I personally am trying to function like this is http://www.wowtah.com/achievements where when you click on the links on the side the info on the page will change. Remember how on wowhead the number in the hyperlink changes? I need it to do that. I need to learn how to do that.

So if it is at all possible to at the very least show me where I can learn this it would be very appreciated. I just really want to continue to progress on my website more. =)

basically you get the link on the side to be:

<a href="http://www.wowtah.com/achievements.php?type=general">General</a><br/>
<a href="http://www.wowtah.com/achievements.php?type=quests">Quests</a><br/>

You can choose to replace the type=general with e.g. type=1, where 1 would be the id from the database.

When you click this link, it will take you back to this page, but with some information in the $_GET array. So in php you can do:

$type = $_GET['type'];
switch ($type) {
  'general': {
    // here you can show your general achievements
    break;
  }
  'quests': {
    // here you can show your quest achievements
    break;
  }
}

Hope you get the idea.

Ok. This makes me happy. This sounds quite simple enough to do. Once I get the hang of it I'm sure I'll get it down.

Now, I took a crack at it, doing what it looked like needed to be done. But, ofcourse, I failed. But I will show you what I did so that way you can show me what I did wrong and how to fix it. =) I didn't wanna make you do all the work so I gave it a shot. =)

So. Here's what I did.

<?php
      $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
      @mysql_select_db('wowtahc1_achievements') or die(mysql_error());
      $type = $_GET['type'];
      switch ($type) {
      'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
	 if ($result)
      {
      while ($row = mysql_fetch_assoc($result))
      {
      echo $row['Name'] . ":     " . $row['Description'] . '<br/>';
      }
      mysql_free_result($result);
      }
      if ($db_link) 
      break;
      }
      'quests': {
     $query = 'SELECT * FROM quests';
      $result = @mysql_query($query) or die(mysql_error());
	 if ($result)
      {
      while ($row = mysql_fetch_assoc($result))
      {
      echo $row['Name'] . ":     " . $row['Description'] . '<br/>';
      }
      mysql_free_result($result);
      }
      if ($db_link) 
      break;
      }
      break;
      }
      }	 	 
      mysql_close($db_link)?>

And then here's the error I get when I try to go to the achievements page:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_CASE or T_DEFAULT or '}' in /home/wowtahc1/public_html/achievements.php on line 243


Line 243 is this line:

'general': {


So, obviously I placed the new php wrongly, haha.

Try this:

<?php
  $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  @mysql_select_db('wowtahc1_achievements') or die(mysql_error());

  $type = $_GET['type'];
  switch ($type) {
    'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo $row['Name'] . ":     " . $row['Description'] . '<br/>';
        }
        mysql_free_result($result);
      }
      break;
    }
    'quests': {
      $query = 'SELECT * FROM quests';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo $row['Name'] . ":     " . $row['Description'] . '<br/>';
        }
        mysql_free_result($result);
      }
      break;
    }
  }      
  mysql_close($db_link)
?>

Nothing changed. = /

Same error.

Ow damn. it should be:

switch ($type) {
  case 'general': {
  }
  case 'quests': {
  }

Sorry about that.

OMG That put a HUGE smile on my face! It worked!! You are simply amazing pritaeas. Seriously, I am so glad I found you. Ahhh this is sooo awesome! I am sooo happy!

I suppose that is all I need for now. Right? I am pretty sure we covered all the issues and questions I had. Thank you thank you thank you SOOO much!

Ok, actually. I do need a bit more help. >_>

I didn't think I would but I do. See here's the thing. I know it is easy to use html tags mingled with the php to edit the text for example if you want to bold text that is put there using php it's not hard. But what about for this instance? How do I edit the php to make the data I placed look pretty? Im talking tables, bold, italic, spacing, perhaps even CSS? Right now it is boring old text squashed on the page with no direction.

Please if you could..=)

Can you give me a specific example ?

Yea Im sorry. I know I'm not clear. I realized the term though of what I am asking. I want to use html tags to make the text from the database look good. Least I think I would use html tags for this. If you used php 'echo' to make text appear I know you can put html tags in the quotes of the text. Anyways, example.

Well, I guess for starters to organize the info perhaps I should put it in a table. Right now the info that shows up is the name of the achievement and the description. Perhaps if I could have all text from 'name' be bold, that might be cool too. I just want to know how I could change the info appearance so that it's not just bunched up and boring looking.

Does that help a little?

If you output your name and description like this:

<table>
 <tr>
  <th class="title">name</th>
 </tr>
 <tr>
  <td class="description">description</td>
 </tr>
</table>

you could use a css file to change the layout, e.g. like this:

th.title {
 font-weight: bold;
 color: #000080;
}
td.description {
 color: #800000;
 font-style: italic;
}

As long as I use 'name' and 'description' as they are used in the database then it will know what I am talking about? Also, then how do I instead of having 'name' and 'description' in the small table example that you used, I have the actual title and description that comes from the database show up? I mean, that would mean I would need php inside the table right? I don't understand where I would place it. Anytime I try putting any html mixed in with the php I get an error on my site again.

The php that I am talking about that I want to do this with is the very thing you generated for me before. the 'case' thing, where I tell the description and name to show up. Using that php, where do I place the html? I know how to do the css part, and really I know the html part no problem too, just not mixed with the php. =P

Am I sounding confusing again? I am doing my best to explain what I am trying to do. I'm mainly confused cuz your post only shows html and css, only changing the look of the word 'name' and 'description'. And that's easy, I know how to use html and css together to do that to text. But it's not text directly that I am doing this to, its generated text from a database. So that text doesn't show in my code while I am creating it, so I'm confused as to where to put the html with the php. Do you get what I am saying? Lol cuz I am confusing myself. I hope you understand me, haha.

Something like this:

<table>
<?php
  $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  @mysql_select_db('wowtahc1_achievements') or die(mysql_error());
 
  $type = $_GET['type'];
  switch ($type) {
    case 'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo '<tr>';
          echo '<th class="title">' . $row['Name'] . '</th>';
          echo '<td class="description">' . $row['Description'] . '</td>';
          echo '</tr>';
        }
        mysql_free_result($result);
      }
      break;
    }
    case 'quests': {
      $query = 'SELECT * FROM quests';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
        while ($row = mysql_fetch_assoc($result))
        {
          echo '<tr>';
          echo '<th class="title">' . $row['Name'] . '</th>';
          echo '<td class="description">' . $row['Description'] . '</td>';
          echo '</tr>';
        }
        mysql_free_result($result);
      }
      break;
    }
  }      
  mysql_close($db_link)
?>
</table>

Erg sorry double post.

Woot woot ok this is good. Let me mess around with this, in the meantime... I do have another question to ask. Hope you don't mind, you have been so good to me. >_>

Alright, you've wonderfully showed me how to pull up data from the entire table, but now how do I do the same thing except for only one specific record on a table? For example, we'll go back to good old http://wowhead.com. You can search their databases that bring up items, but you can also look at one specific item, it creates a page just have we have done with my tables. How do you do that?

Hope that's simple enough, ask if you need a better explanation, I think I did good.

Actually a more personal example..on my site, I have data show of the name and the description of the achievement. Well each name represents a new achievement. I want to be able to take one specific achievement and show only that just as I show only one table from the database right now. For example, on http://www.wowtah.com/achievements.php?type=general the first achievement is "Level 10". I want the user to be able to click on the achievement and just as the tables do, the info changes to whatever I want it to show then. Does that make sense? So that I could have a section that explains how to gain the achievement, granted, this one in particular doesn't need much explaining.

It would be something like this. I assume you have a column 'id' in your tables that identifies each separate record.

<table>
<?php
  $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  @mysql_select_db('wowtahc1_achievements') or die(mysql_error());

  $id = isset($_GET['id']) ? $_GET['id'] : 0;
 
  $type = $_GET['type'];
  switch ($type)
  {
    case 'general': {
      if ($id < 1) 
      {
        $query = 'SELECT * FROM general';
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          while ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title"><a href="achievements.php?type=general&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      else
      {
        $query = "SELECT * FROM general WHERE id=$id";
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          if ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title">' . $row['Name'] . '</th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      break;
    }
    case 'quests':
    {
      if ($id < 1)
      {
        $query = 'SELECT * FROM quests';
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          while ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title"><a href="achievements.php?type=quests&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      else
      {
        $query = "SELECT * FROM quests WHERE id=$id";
        $result = @mysql_query($query) or die(mysql_error());
        if ($result)
        {
          if ($row = mysql_fetch_assoc($result))
          {
            echo '<tr>';
            echo '<th class="title">' . $row['Name'] . '</th>';
            echo '<td class="description">' . $row['Description'] . '</td>';
            echo '</tr>';
          }
          mysql_free_result($result);
        }
      }
      break;
    }
  }      
  mysql_close($db_link)
?>
</table>

Thanks again priteas. :) I am sure that code will work excellently. I just haven't had a chance to have a go with it. Been so busy with school and work I'm finally now replying to you.

So. I do have another question. I added another field to my database, a blob type like you told me to use for pictures. I attached the picture and then I tried having that also show up on my site and it turned everything into mumbo jumbo. Is there some special way you add a blob field? Do I gotta do something different than I do with these varchar type fields? Here is what the part of my code that I edited looked like:

case 'general': {
      $query = 'SELECT * FROM general';
      $result = @mysql_query($query) or die(mysql_error());
      if ($result)
      {
      while ($row = mysql_fetch_assoc($result))
      {
      echo '<br/>' . '<br/>';
      echo $row['Picture'] . '<span class="title">' . $row['Name'] . '</span>';
	  echo '<br/>';
	  echo '<span class="description">' . $row['Description'] . '</span>';
      }
      mysql_free_result($result);
      }
      break;
      }

Whats highlighted in red is what I added. Before that, everything works fine. I even tried replacing 'Name' with 'Picture' just to see if I added the php wrong, but, still same problem. Um, and I guess to make it easier to see what issue is MAYBE the mumbo jumbo that appeared might be useful....

PNG IHDR@@iqmIDATxݛmp[ՙ֕4Wm`b<4i:S~t>v:~`ٲہfg`w3NSR@`j1a#GX*[Eҽx=<9yιM, EHʸ]~)ݵK^L_}| M(5e:rԧ(keyȾs@pxxG~){C=@xפ@8`ȭxi%y\ddx!GF2qFQa+HeT>x@Pѹ5\u) CЕߧg(51x +|؄:ij:gPޠ *T̼v*-$:[

Thats just a small portion of it, but it all looks basically like that, hehe.

lol dont mind the confused smiley in the middle of the mumbo jumbo, it must have had the correct symbols in the correct spot to make that, hahaha.

A blob field is just binary data, which in your code gets displayed as text. The most easy way would be to create a separate php page that retrieves your image and displays it. I have an example of this in my original admin panel. I'll need some time to make an example for you.

This thread has a working example, so hopefully you won't need a demo from me: http://www.phpbuilder.com/board/showthread.php?t=10252369

Ok. Um. Yea, that code is a little more confusing looking. Could you maybe explain it a little better than that guy? Cuz I did what he said...but..nothing happened other than I got this on my page:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/wowtahc1/public_html/achievements.php on line 7
">

Line 7 is:

<img src="showavatar.php?id="<?php echo mysql_result($avatardetail, 0, "ID"); ?>">

now I realize it could be because of $avatardetail cuz that could be something from the guy's database but I dont know the equivilence of it to mine. I did name the .php I put the code in called showavatar.php for the sake of simplicity for now so I know that isn't the issue.

But, I don't think that's the only issue we will run into so, lets also solve some others. Here is the code I put in, (for the sake of showing you my changes trying to get it to function with my database):

<?php
require("tools.php");
if(isset($id))
{
    $filedata = mysql_query("SELECT * FROM general WHERE ID = '".$id."' LIMIT 1");
    header("Content-type: \"".mysql_result($filedata, 0, "filetype")."\"");
// Work out whether we can show or download the attachment:
    $mimetype = explode("/", $row["filetype"]);
    if($mimetype[0] != "Picture")
    {
        header("Content-length: ".mysql_result($filedata, 0, "filesize"));
        header("Content-Disposition: attachment; filename=".mysql_result($filedata, 0, "filename"));
        header("Content-Description: PHP Generated Data");
    }
    echo mysql_result($filedata, 0, "Avatar");
}
?>

I highlighted in red again the changes that I made. I think also I should change "Avatar"? but I dont know to what. Also, I don't see how in this code I can place the image where I want it....

Also, whats tools.php? That code says it requires it and, I can see it on my tabs, it's there, but it's blank.

You can remove the require(tools), it's something from the other guys code.

You shouldn't have changed "image" into "Picture".

I have a very busy week this week, so I haven't got around to making you a demo.

Oh its no problem. You take your time. I'm in no hurry.

Ok well it's still having a problem with the same line and I still don't understand how I tell it where to put the image.

So whenever you do get a chance to make that demo that would be superb. But like I said before, no rush.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.